Reputation: 960
I'm creating an Android App that ask the user for this permissions: Default Login permission + user_friends + publish_action.
In my first activity i did the Login + ask the "user_friends" permission and work great.
Now in my Second Activity i want to ask for the "publish_action" permission after a AlertDialog choice. The problem is that i never been promped for the "publish_action" box, the app skip the request and go ahead calling another Activity (Leaderboards)
Here is my Second Activity:
CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
final Context context = this;
//stuff
b_exit.setOnClickListener(new View.OnClickListener()
{
public void onClick(View V)
{
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(getString(R.string.salva_dati))
.setCancelable(true)
.setPositiveButton(getString(R.string.si), new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
askForFBPublishPerm();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.clear();
editor.apply();
Intent intent = new Intent(getApplicationContext(), Leaderboard.class);
startActivity(intent); // IT START WITHOUT ASK ME THE PERMISSION
}
}
}
})
}
void askForFBPublishPerm(){
Log.d("perm", "asking for the permissions"); //I SEE THAT LOG BUT NOTHING MORE AFTER THAT LINE
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithPublishPermissions(this,Arrays.asList("publish_actions"));
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("perm", "SUCCESS");//I DONT SEE THAT LOG
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "cancelled while asking publish permission", Toast.LENGTH_LONG).show();
Log.d("perm", "cancelled while asking publish permission");
//I DONT SEE THAT LOG
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getApplicationContext(), "error occurred while asking publish permission!", Toast.LENGTH_LONG).show();
Log.d("perm", "error occurred while asking publish permission!"); //I DONT SEE THAT LOG
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
In my Log i see that askForFBPublishPerm() as been called but it never enter in onSuccess() or onCancel() or onError().
I also get reviewed my app by Facebook and they gave me the "publish_action" permission.
This "publish_action" request dont work and i dont know why, someone can help me? Thanks in advice
Upvotes: 0
Views: 260
Reputation: 838
Handle your callbackManager in onActivityResult. Just apply this code.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data); // this line is required
}
Upvotes: 1