Facebook SDK 指令对应用程序 ID 没有意义

Facebook SDK instruction not making sense about app id

我拍下了下面的Facebook说明。它有什么问题?我的应用程序不断崩溃,但出现有关 ApplicationId 不应为空的异常。但是我在清单中将我的应用程序 ID 添加为 <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>;这是在 strings.xml 资源中将其作为字符串添加为 <string name="facebook_app_id">0000000000</string>

之后

所以我认为说明是错误的,因为它没有说要添加哪个 uses-permission,而是说用值 Facebook_app_id 调用字符串资源键 com.facebook.sdk.ApplicationId。这里是linkhttps://developers.facebook.com/docs/android/getting-started#eclipse

很简单

1.) 在 Facebook 上创建应用程序,获取 app_id 您随后将用于附加到您的应用程序。

2.) 在 AndroidManifest.xml 中定义您的 applicationId,如下所示:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

<application android:label="@string/app_name".... 标签下 其中 app_id 是 strings.xml.

中的一个字符串

示例(Facebook 示例应用程序):

<application android:label="@string/app_name"
                 android:icon="@drawable/icon"
                 android:theme="@android:style/Theme.NoTitleBar"
            >
        <activity android:name=".HelloFacebookSampleActivity"
                  android:label="@string/app_name"
                  android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.LoginActivity"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:label="@string/app_name" />
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
    </application>

注意在<application>标签下添加的值 并在 strings.xml(确保这样做)

<string name="app_id">xxxxxxxxxxxx</string>

3.) 在清单中设置权限

<uses-permission android:name="android.permission.INTERNET"/>

这是一项 android 要求,因此该应用程序可以访问互联网。

所以有了权限,上面的清单看起来像

<uses-permission android:name="android.permission.INTERNET" />
 <application android:label="@string/app_name"
                     android:icon="@drawable/icon"
                     android:theme="@android:style/Theme.NoTitleBar"
                >
            <activity android:name=".HelloFacebookSampleActivity"
                      android:label="@string/app_name"
                      android:windowSoftInputMode="adjustResize">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <activity android:name="com.facebook.LoginActivity"
                      android:theme="@android:style/Theme.Translucent.NoTitleBar"
                      android:label="@string/app_name" />
            <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
        </application>

我遇到了同样的问题。这就是我解决它的方法——我想。至少做了这些之后,问题就解决了。

在strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
….
<string name="com.facebook.sdk.ApplicationId">facebook_app_id</string>
<string name="facebook_app_id">111111111</string>
….
</resources>

清单中

<application
… >

<meta-data
  android:name="com.facebook.sdk.ApplicationId"
  android:value="@string/facebook_app_id" />
</application>

</manifest>

注意 strings.xml 文件中有两个条目。