i want to display only one button 'publish on facebook' in my app android !!! (don't display login facebook) !
when i click on 'publish on facebook', i want to : . if 'session facebook' is null : display 'login facebook' and publish automaticaly . if 'session facebook' is don't null : publish automaticaly
i try this but it is not ok ! when i close 'login facebook', the window close and reopen :-(
Thanks you very much for you helppppppppppppppppppppppppppppp
public class ExperienceDetailActivity extends Activity {
private LoginButton loginButton;
private Button postImageBtn;
private UiLifecycleHelper uiHelper;
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
static boolean publishToFB;
static Button button_detail_FB;
static Button buttonFB;
public void postImage() {
if (checkPermissions()) {
Request uploadRequest = Request.newUploadPhotoRequest(Session.getActiveSession(), img, new Request.Callback() {
@Override
public void onCompleted(Response response) {
if (response.getError() == null)
Toast.makeText(ExperienceDetailActivity.this, getString(R.string.str_Facebook_Partage_OK), Toast.LENGTH_SHORT).show();
else {
Toast.makeText(ExperienceDetailActivity.this, getString(R.string.str_Facebook_Partage_KO), Toast.LENGTH_SHORT).show();
}
}
});
Bundle params = uploadRequest.getParameters();
Float note = Experience.getNote();
params.putString("message", getString(R.string.str_Facebook_Partage_Text));
uploadRequest.setParameters(params);
uploadRequest.executeAsync();
}
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
buttonFB.performClick();
}
}
public boolean checkPermissions() {
Session s = Session.getActiveSession();
if (s != null) {
return s.getPermissions().contains("publish_actions");
} else
return false;
}
@Override
public void onResume() {
uiHelper.onResume();
super.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
if (publishToFB == true) {
buttonFB.performClick();
}
}
@Override
public void onSaveInstanceState(Bundle savedState) {
super.onSaveInstanceState(savedState);
uiHelper.onSaveInstanceState(savedState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_experience_detail);
Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, callback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
}
loginButton = (LoginButton) findViewById(R.id.button_detail_LoginFB);
buttonFB = (Button) findViewById(R.id.button_detail_FB);
loginButton.setPublishPermissions(Arrays.asList("publish_actions"));
buttonFB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Session session = Session.getActiveSession();
if (session != null) {
if (session.getState() == SessionState.CREATED_TOKEN_LOADED) {
session.openForRead(null);
}
if (session.getState() == SessionState.OPENED) {
postImage();
} else {
publishToFB = true;
loginButton.performClick();
}
} else {
publishToFB = true;
loginButton.performClick();
}
}
});
}
Aucun commentaire:
Enregistrer un commentaire