且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Facebook Android SDK未注册安装

更新时间:2023-10-11 21:42:58

在我的情况下,问题是将meta添加到调试清单


I created an app in Unity and published it to an Eclipse Android project, then I included the Facebook SDK in the project, I also followed the getting started wizard in the developer site.

I added the following line of code to the onResume() function of my main activity:

com.facebook.AppEventsLogger.activateApp(this, "MY FB APP ID");

In the Manifest file of the app I added the following:

<activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:name="com.facebook.unity.FBUnityLoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
    </activity>
    <activity android:configChanges="keyboardHidden|orientation" android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
    </activity>
    <activity android:exported="true" android:name="com.facebook.unity.FBUnityDeepLinkingActivity">
    </activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />

I also added the FB app Id to the strings.xml file in res/values folder.

I generated a Hash Key (in windows) with the following command in command prompt:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

Which generated a 28 character string, but I still did not see any app installs registered on Android. So after searching more I found the following code on this page https://developers.facebook.com/docs/android/getting-started

    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.hellofacebook", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

I changed the package name from "com.facebook.samples.hellofacebook" to the package name of my app, added it to the onCreate() function of the main activity, and ran the code, which logged a hash key. I copied the returned key into the app settings on the facebook developer site, but I am still not getting any installs or events registering on Android.

I also have an iOS version of the app and there everything is working perfectly.

I would really appreciate any suggestions/ideas/anything as to how to get the Facebook SDK to register installs and events on Android.

in my case the problem was adding the meta to the debug manifest