登录Facebook

时间:2016-02-11 08:48:24

标签: android facebook facebook-graph-api

我尝试在登录Facebook时启动另一项活动,但它始终停留在startActivity(intent) 我检查了它说have you declared this activity in your AndroidManifest.xml?的错误消息,我在Manifest中添加了这个活动 在这里坚持了三天,请帮忙

Mainfest

 <activity
        android:name=".Workout"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="com.addtw.aweino1.WORKOUT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

这是代码:

 public class FacebookLogin extends Activity {

CallbackManager callbackManager;
private AccessToken accessToken;
Intent intent =new Intent(FacebookLogin.this,com.addtw.aweino1.Workout.class);

@Override
protected void onCreate(Bundle savedInstanceState) {
    FacebookSdk.sdkInitialize(getApplicationContext());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebooklogin);
    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.FaceBooklogin_button);

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            accessToken = loginResult.getAccessToken();
            Log.d("FB", "access token got.");
            Toast.makeText(FacebookLogin.this, "Gooooooooood", Toast.LENGTH_LONG).show();
            GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.d("FB", "complete");
                    Log.d("FB", object.optString("name"));
                    Log.d("FB", object.optString("link"));
                    Log.d("FB", object.optString("id"));
                    Log.d("FB", object.optString("gender"));
                    TextView textUSERname;
                    textUSERname = (TextView) findViewById(R.id.textUSERname);
                    String id = object.optString("id");
                    String name = object.optString("name");
                    textUSERname.setText("Yo!!!! wellcome :" + name);
                    ImageView userPhoto = (ImageView) findViewById(R.id.imageFB_user);
                    String i = "http://graph.facebook.com/" + id + "/picture?type=large";
                    Glide.with(FacebookLogin.this).load(i).override(200, 200).into(userPhoto);
                    startActivity(intent);  //<---ERROR can't fine activity
                }
            });
            //做你要做的事
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,link,gender");
            request.setParameters(parameters);
            request.executeAsync();


        }


        @Override
        public void onCancel() {
            Log.d("FB", "CANCEL");
            Toast.makeText(FacebookLogin.this, "CANCLE", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(FacebookLogin.this, "Error", Toast.LENGTH_LONG).show();
        }
    });



}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    callbackManager.onActivityResult(requestCode, resultCode, data);

}

@Override
protected void onResume() {
    super.onResume();
    AppEventsLogger.activateApp(this);
}


@Override
protected void onPause() {
    super.onPause();
    AppEventsLogger.deactivateApp(this);

}


}

这是错误消息

208/com.addtw.aweino1 E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.addtw.aweino1, PID: 24208
                                                               android.content.ActivityNotFoundException: Unable to find explicit activity class {/com.addtw.aweino1.Workout}; have you declared this activity in your AndroidManifest.xml?
                                                                   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1791)
                                                                   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1513)
                                                                   at android.app.Activity.startActivityForResult(Activity.java:3933)
                                                                   at android.app.Activity.startActivityForResult(Activity.java:3881)
                                                                   at android.app.Activity.startActivity(Activity.java:4204)
                                                                   at android.app.Activity.startActivity(Activity.java:4172)
                                                                   at com.addtw.aweino1.FacebookLogin$1$1.onCompleted(FacebookLogin.java:83)
                                                                   at com.facebook.GraphRequest$1.onCompleted(GraphRequest.java:304)
                                                                   at com.facebook.GraphRequest$5.run(GraphRequest.java:1368)
                                                                   at android.os.Handler.handleCallback(Handler.java:739)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                   at android.os.Looper.loop(Looper.java:135)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5910)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

1 个答案:

答案 0 :(得分:1)

请在Intent intent =new Intent(FacebookLogin.this,com.addtw.aweino1.Workout.class); startActivity(intent);

中添加此代码
261233