1.Sign up for FaceBook 's developer account and create apps.
2.Download and install the Android Facebook SDK and import into Eclipse
:Https://developers.facebook.com/docs/android/?locale=zh_CN
3, in your project correctly import Lib, mainly to import the Facebook SDK, such as:
4.then open res/values/strings.xml, add the string "facebook_app_id"
Where:appId is automatically generated when you register an app on Facebook
5. Configure androidmanifest.xml, add permissions and Meta-data
<uses-permission android:name= "Android.permission.INTERNET"/> <meta-dataandroid:name= " Com.facebook.sdk.ApplicationId "android:value=" @string/facebook_app_id "/>
6. Then go back to the Facebook app and fill in the name of the package name and the main Activity.
7. Use code to view key hash, add this code and run
try {packageinfo info = Getpackagemanager (). Getpackageinfo ("Com.example.kam", packagemanager.get_signatures); for ( Signature signature:info.signatures) {messagedigest MD = messagedigest.getinstance ("SHA"); Md.update ( Signature.tobytearray ()); LOG.E ("Keyhash:", Base64.encodetostring (Md.digest (), Base64.default));}} catch (Namenotfoundexception e) {} catch (NoSuchAlgorithmException e) {}
Eg. after running, get: sglgmxlutbyuyk34ffufgzdypb8=
Ps. It is important to note that the new version of Eclipse New project, if can be compatible with the old version and automatically generate appcompat_v7 This package, May and FACEBOOKSDK inside of the conflict. Duplicate class libraries are used and the versions are inconsistent. Causes the lower version to be used preferentially. All we have to do is delete the APPCOMPAT_V7 library.
8. In order to output the log of the program activity event, the on Resume () method in the main activity is added The following code:
@Override protected void Onresume () { super.onresume (); Logs ' Install ' and ' app activate ' app Events. Appeventslogger.activateapp (this); }
Ps. the official website of the document to be in the onPause () also add this sentence, but measured, will error, so delete it.
Android Learning Notes Facebook SDK Preparation conditions