首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android facebook applicationId不能为空

Android facebook applicationId不能为空
EN

Stack Overflow用户
提问于 2013-04-23 05:15:30
回答 5查看 40K关注 0票数 71

我一直在遵循下面的教程,将我的应用程序与Facebook集成。Facebook tutorial

我遵循了教程中的所有内容,但我已经在两个案例中获得了applicationId cannot be null,这真的很令人沮丧。

我的FacebookActivity onCreate包含以下内容,与教程中的内容完全相同:

代码语言:javascript
复制
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    setContentView(R.layout.main_fb);

    FragmentManager fm = getSupportFragmentManager();
    fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
    fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);

    FragmentTransaction transaction = fm.beginTransaction();
    for(int i = 0; i < fragments.length; i++) 
    {
        transaction.hide(fragments[i]);
    }
    transaction.commit();
}

但是,当我尝试显示该活动时,得到的结果是applicationId cannot be null,而LogCat将我指向的行是:uiHelper.onCreate(savedInstanceState);

然后我尝试注释掉这一行,然后该活动就会显示出来。然而,现在当我单击LoginButton时,我得到了同样的错误,但这次是指向facebook的LoginButton类中的applicationId字段。

我已经在我的字符串值和清单中包含了Id,如下所示:

代码语言:javascript
复制
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_ID"/>

我试着用代码获取Id,但是什么都没有改变。

到底是什么导致了这一切?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-04-23 05:19:13

TL;DR:您让将应用程序的ID写入您的strings.xml中,然后引用(即@strings/fb_app_id),因为如果您将其直接(作为值)放入AndroidManifest.xml中,它将不起作用。

您必须在AndroidManifest.xml中定义applicationId,如下所示:

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

<application android:label="@string/app_name"....标签下

其中app_idstrings.xml中的字符串。

示例:

代码语言:javascript
复制
 <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>

**请注意,<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/><application>标签内

--在strings.xml中

代码语言:javascript
复制
<string name="app_id">1389xxxxxxxx</string>
票数 226
EN

Stack Overflow用户

发布于 2016-06-17 06:48:31

从今天开始答案就不太正确了。如果有人没有使用这个:AppEventsLogger.activateApp(this);

自上次更新以来,您必须这样做,否则您的应用程序将崩溃。您还应该在此处传递应用程序,而不是Context

https://developers.facebook.com/docs/android/getting-started

代码语言:javascript
复制
// Add this to the header of your file:
import com.facebook.FacebookSdk;

public class MyApplication extends Application {
    // Updated your class body:
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the SDK before executing any other operations,
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
    }
}
票数 8
EN

Stack Overflow用户

发布于 2015-04-09 00:01:07

问题是id正在被转换为整数:https://code.google.com/p/android/issues/detail?id=78839

在我的例子中,facebook_app_id是根据每个风格从build.gradle文件中设置的。

解决方案是用"包装id。

代码语言:javascript
复制
flavor.resValue "string", "facebook_app_id", "\"1111111111111\""

或者,如果你更愿意避免转义:

代码语言:javascript
复制
flavor.resValue "string", "facebook_app_id", '"1111111111111"'
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16156856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档