我正在使用facebook sdk 4.14它正在设备上运行哪些剂量有Facebooklite app
FacebookSdk.sdkInitialize(MainActivity.this);
final Dialog dlg = new Dialog(MainActivity.this);
dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
dlg.setContentView(R.layout.fblogindilog);
TextView continuew=(TextView)dlg.findViewById(R.id.cont);
TextView fbusername=(TextView)dlg.findViewById(R.id.usname);
lgnfb = (LoginButton) dlg.findViewById(R.id.fblogin);
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken == null) {
dlg.show();
lgnfb.setReadPermissions(Arrays.asList("public_profile, email, user_birthday"));
callbackManager = CallbackManager.Factory.create();
lgnfb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
GetNameId(object);
}
});
Bundle parameters=new Bundle();
parameters.putString("fields","id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
dlg.dismiss();
Intent intent = new Intent(MainActivity.this, Sujab.class);
startActivity(intent);
}
@Override
public void onCancel() {
Toast.makeText(MainActivity.this, "login cancled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(MainActivity.this, "unable to connect with facebook your internet is slow", Toast.LENGTH_SHORT).show();
}
});
}
else {
continuew.setText("Continue with same account");
SharedPreferences sp=getSharedPreferences("USERINFO",Context.MODE_PRIVATE);
String namefb=sp.getString("Name"," ");
fbusername.setText("Welcome! "+namefb);
dlg.show();
continuew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Sujab.class);
startActivity(intent);
}
});
lgnfb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "You are sucessfuly logout please login for sujab", Toast.LENGTH_SHORT).show();
dlg.dismiss();
}
});
和
private void GetNameId(JSONObject object) {
try {
name=object.getString("name");
userid=object.getString("id");
Log.d("Name::",name);
Log.d("id::",userid);
sharedPreferences= getSharedPreferences("USERINFO",Context.MODE_PRIVATE);
SharedPreferences.Editor ed=sharedPreferences.edit();
ed.putString("Name",name);
ed.putString("Id",userid);
ed.clear();
ed.commit();
}catch (Exception e){
e.printStackTrace();
}
}
但是当我在装有Facebooklite app的设备上安装这个apk时,它会直接打开facebooklite有什么问题?
答案 0 :(得分:0)
尝试在初始化callbackManager后添加以下行:
lgnfb.setLoginBehavior(LoginBehavior.WEB_ONLY);