gpt4 book ai didi

android - GCMRegistrar checkManifest 使我的应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 03:29:25 26 4
gpt4 key购买 nike

我在使用 GCMRegistrar 时遇到问题,这是代码:

// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this); <- this line is the problem (I suppose)
regId = GCMRegistrar.getRegistrationId(this);

当我将该行更改为评论时,应用程序不会崩溃,但 regId 为空,当我尝试使用该行时,它会使我的应用程序崩溃,我不知道为什么,所以我希望你能帮助我. :)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chattest1"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

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

<permission
android:name="com.example.chattest1.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.example.chattest1.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.chattest1.RegisAct"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.chattest1.Main"
android:label="@string/title_activity_regis" >
</activity>
</application>

</manifest>

最佳答案

checkManifest 检查您的 list 是否包含 GCM 工作所需的定义。当缺少某些内容时,它会抛出 IllegalStateException

在您的情况下,您缺少可以从 GCM 接收消息的广播接收器。

GCMRegistrar.getRegistrationId(this)(返回本地存储的注册 ID)仅当您首先调用 GCMRegistrar.register 时才会返回非空值。请注意,GCMRegistrar.register 是非阻塞的,因此响应不会立即到达。

最后,正如 CommonsWare 所建议的那样,GCMRegistrar 已被弃用,我们鼓励您改用 GoogleClassMessaging 类。

关于android - GCMRegistrar checkManifest 使我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17734016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com