我已经按照教程: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
但是当我运行项目时会出现问题。
这是我的完整代码:
package com.example.firstandroidapp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.model.*;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
这是我的logcat:
07-09 13:38:11.960: E/WindowManager(2015): Activity com.facebook.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40573978 that was originally added here
07-09 13:38:11.960: E/WindowManager(2015): android.view.WindowLeaked: Activity com.facebook.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40573978 that was originally added here
07-09 13:38:11.960: E/WindowManager(2015): at android.view.ViewRoot.<init>(ViewRoot.java:263)
07-09 13:38:11.960: E/WindowManager(2015): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
07-09 13:38:11.960: E/WindowManager(2015): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-09 13:38:11.960: E/WindowManager(2015): at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-09 13:38:11.960: E/WindowManager(2015): at android.app.Dialog.show(Dialog.java:241)
07-09 13:38:11.960: E/WindowManager(2015): at com.facebook.widget.WebDialog$DialogWebViewClient.onPageStarted(WebDialog.java:362)
07-09 13:38:11.960: E/WindowManager(2015): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:266)
07-09 13:38:11.960: E/WindowManager(2015): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 13:38:11.960: E/WindowManager(2015): at android.os.Looper.loop(Looper.java:130)
07-09 13:38:11.960: E/WindowManager(2015): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-09 13:38:11.960: E/WindowManager(2015): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 13:38:11.960: E/WindowManager(2015): at java.lang.reflect.Method.invoke(Method.java:507)
07-09 13:38:11.960: E/WindowManager(2015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-09 13:38:11.960: E/WindowManager(2015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-09 13:38:11.960: E/WindowManager(2015): at dalvik.system.NativeStart.main(Native Method)
最后,谢谢你的关注!