Android下使用最新FaceBook SDK 3.0(4)

3、MainActivity 类 ,继承FragmentActivity类  ,初始化 添加MainFragment 类,打印哈希值可写可不写

package com.thirdfacebook;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import Android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

private MainFragment mainFragment;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  if (savedInstanceState == null) {
        // Add the fragment on initial activity setup
        mainFragment = new MainFragment();
        getSupportFragmentManager()
        .beginTransaction()
        .add(android.R.id.content, mainFragment)
        .commit();
    <SPAN> </SPAN> } else {
      <SPAN> </SPAN>  // Or set the fragment from restored state info
      <SPAN> </SPAN>  mainFragment = (MainFragment) getSupportFragmentManager()
      <SPAN> </SPAN>  .findFragmentById(android.R.id.content);
    <SPAN> </SPAN> }
 
  /**
  * 打印哈希值
  */
  try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.firstfacebook",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}
 }


 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }
}

4、AndroidMainfest.xml 添加 facebook LoginActivity(登录activity)

<activity android:name="com.facebook.LoginActivity"/>

5、运行项目 成功运行后登录按钮变成Log Out, 点击Log Out则注销

Android下使用最新FaceBook SDK 3.0

Android下使用最新FaceBook SDK 3.0

Android下使用最新FaceBook SDK 3.0

Android下使用最新FaceBook SDK 3.0

如果错误,请大牛多多指出!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/364f97b34d39fd6718775d6abda7e6f7.html