我正在创建一个向用户询问此权限的Android应用:默认登录权限+ user_friends + publish_action。
在我的第一个活动中,我做了登录+询问" user_friends"许可和工作很棒。
现在在我的第二个活动中,我想要求" publish_action" AlertDialog选择后的权限。 问题是我从未被提示过" publish_action"框,应用程序跳过请求并继续调用另一个活动(排行榜)
这是我的第二项活动:
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);
}
在我的Log中,我看到askForFBPublishPerm()被调用但它从未进入onSuccess()或onCancel()或onError()。
我也通过Facebook审核了我的应用程序,他们给了我&#34; publish_action&#34;权限。
这&#34; publish_action&#34;请求不工作,我不知道为什么,有人可以帮助我吗?谢谢你的建议
答案 0 :(得分:1)
在onActivityResult中处理你的callbackManager。只需应用此代码即可。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data); // this line is required
}