我无法同时使用模拟器和手机登录 Facebook。手机确实给了我 Facebook 的登录屏幕,但是在我输入用户名和密码后,按钮图像没有改变 + 我收到错误消息“无法找到 com.facebook.katana.provider.AttributionIdProvider 的提供商信息”。尝试从我的手机登录时,FB 登录页面会打开大约 2 秒钟,然后立即关闭回到我的布局。
怎么了?
package com.test.facebookapp;
import java.io.IOException;
import java.net.MalformedURLException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
public class StartingPlace extends Activity implements OnClickListener{
Facebook fb;
ImageView pic,button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String APP_ID = getString(R.string.APP_ID);
button = (ImageView)findViewById(R.id.login);
pic = (ImageView)findViewById(R.id.picture_pic);
button.setOnClickListener(this);
fb = new Facebook(APP_ID);
updateButtonImage();
}
private void updateButtonImage() {
// TODO Auto-generated method stub
if (fb.isSessionValid()){
button.setImageResource(R.drawable.logout_button);
}
else{
button.setImageResource(R.drawable.login_button);
}
}
@Override
public void onClick(View v) {
if (fb.isSessionValid()){
//button will close session - logout
try {
fb.logout(getApplicationContext());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
updateButtonImage();
}
else{
//login to facebook
fb.authorize(StartingPlace.this, new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Toast.makeText(StartingPlace.this, "fbError", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
Toast.makeText(StartingPlace.this, "DialogError", Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
updateButtonImage();
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(StartingPlace.this, "onCancel", Toast.LENGTH_SHORT).show();
}
});
}
// TODO Auto-generated method stub
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.facebookapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.test.facebookapp.StartingPlace"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity"></activity>
</application>
</manifest>
谢谢!