我正在尝试完成以下入门步骤谷歌的GCM http://developer.android.com/guide/google/gcm/gs.html来自 Google 的 Android 开发者网站。
当我的设备尝试注册时,由于以下原因而失败:
Activity 已从最初在此处注册的 com.google.android.gcm.GCMBroadcastReceiver 泄漏了 IntentReceiver。您是否错过了对 unregisterReceiver 的调用?
这是代码:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, senderId); // <-- It fails here
} else {
Log.v("GCM", "Already registered");
}
任何想法?
我究竟做错了什么?
Update
这是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission android:name="com.sample.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.sample.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".sample"
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:theme="@android:style/Theme.NoTitleBar" android:name=".Main" android:screenOrientation="portrait" />
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.sample" />
</intent-filter>
</receiver>
<service android:name="com.sample.GCMIntentService" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
最后它起作用了。
我需要做的就是打电话给GCMRegistrar.onDestroy(this)
in the onDestroy()
我正在调用的同一上下文中的方法GCMRegistrar.register()
在这里找到:Google Cloud Messaging 中泄露的 IntentReceiver https://stackoverflow.com/questions/11299312/leaked-intentreceiver-in-google-cloud-messaging
感谢您的支持 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)