[英]Google Cloud Messaging / GCM
我想將GCM添加到我的應用程序中,但清單存在一些問題。 這是我的清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.comanderkai77.gssvertretungsplan"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<permission
android:name="de.comanderkai77.gssvertretungsplan.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="de.comanderkai77.gssvertretungsplan.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service android:name=".GCM" />
<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="de.comanderkai77.gssvertretungsplan" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
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=".GCM_Intent" >
</activity>
</application>
</manifest>
Java代碼還可以。 當我調用GCMRegistrar.register(MainActivity.this,GCM.SENDER_ID); 什么都沒發生。 日志貓說沒什么用。 您有解決此問題的想法嗎?
GCMRegistrar似乎已棄用。
您可以嘗試GoogleCloudMessaging :但是,此類需要Google Play服務版本3.1或更高版本。
GoogleCloudMessaging文檔頁面中有一個有用的代碼塊。 因此,您將獲得一些有用的信息,以了解可能是問題所在,可能是您無法訪問googlecloudmessaging服務或其他原因,並使用這些錯誤控制語句包裝代碼。
// Check device for Play Services APK. If check succeeds, proceed with
// GCM registration.
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.isEmpty()) {
registerInBackground();
}
} else {
Log.i(TAG, "No valid Google Play Services APK found.");
}
順便問一下,它是否與gcm正確通信? 是返回設備的registerId還是其代碼有任何錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.