API 2.3 Google云端通讯仅获得注册事件 [英] API 2.3 GoogleCloudMessaging get only registration event
问题描述
在code是非常简单和完美的工作在API> = 3.0,但如果我开始在API 2.3,我发现了问题 - 谷歌只发送注册事件:
保护无效onHandleIntent(意向意图){ 捆绑额外= intent.getExtras();
Google云端通讯GCM = GoogleCloudMessaging.getInstance(本); 字符串为messageType = gcm.getMessageType(意向); 如果(!extras.isEmpty()){ 如果(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(为messageType)){
// sendNotification的(发送错误:+ extras.toString()); }否则如果(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(为messageType)){
// sendNotification时(在服务器上删除的邮件:+ extras.toString()); //如果是一个普通GCM消息,做了一些工作。
}否则如果(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(为messageType)){ //我们在这里,如果API> = 3.0 }
否则,如果(isRegistrationIntent(意向)){ //我们在这里IF API 2.3< ----- BUG
}
}
//释放该WakefulBroadcastReceiver提供的唤醒锁。
GcmBroadcastReceiver.completeWakefulIntent(意向);
}
注册是成功的。但在此之后,我的索尼Хperia(API 2.3)只得到登记的事件:从另一设备发送的GCM-消息,但的Xperia接收登记的通知。魔法; (
有谁知道可能的原因?
清单:
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.fenix14
安卓版code =2
机器人:=的versionNameDVA><用途-SDK
安卓的minSdkVersion =10
机器人:targetSdkVersion =19/><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/><! - GCM设置 - >
<使用许可权的android:NAME =android.permission.GET_ACCOUNTS/>
<使用许可权的android:NAME =android.permission.WAKE_LOCK/>
<使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/><允许机器人:名字=com.fenix14.utils.permission.C2D_MESSAGE
安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.fenix14.utils.permission.C2D_MESSAGE/><! - / GCM设置 - ><应用
机器人:allowBackup =真
机器人:名字=com.fenix14.utils.FenixApp
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ FenixActionBarTheme>
<! - GCM设置 - > <元数据机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/> <接收
机器人:名字=com.fenix14.gcm.GcmBroadcastReceiver
机器人:权限=com.google.android.c2dm.permission.SEND>
&所述;意图滤光器>
<作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
<作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>
<类机器人:名字=com.fenix14.gcm/>
&所述; /意图滤光器>
< /接收器> <服务机器人:名字=com.fenix14.gcm.GcmIntentService/> <! - / GCM设置 - > <活动
机器人:名字=com.fenix14.entry.MainActivity
机器人:主题=@风格/ FenixActionBar.NoActionBar>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>< /清单>
您清单有许多不一致的:
包=com.fenix14<允许机器人:名字=com.fenix14.utils.permission.C2D_MESSAGE
安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.fenix14.utils.permission.C2D_MESSAGE/><接收
机器人:名字=com.fenix14.gcm.GcmBroadcastReceiver
机器人:权限=com.google.android.c2dm.permission.SEND>
&所述;意图滤光器>
<作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
<作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>
<类机器人:名字=com.fenix14.gcm/>
&所述; /意图滤光器>
< /接收器>
您应该在所有的GCM相关的地方使用相同的包名,所以它应该是:
包=com.fenix14<允许机器人:名字=com.fenix14.permission.C2D_MESSAGE
安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.fenix14.permission.C2D_MESSAGE/><接收
机器人:名字=com.fenix14.gcm.GcmBroadcastReceiver
机器人:权限=com.google.android.c2dm.permission.SEND>
&所述;意图滤光器>
<作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
<作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>
<类机器人:名字=com.fenix14/>
&所述; /意图滤光器>
< /接收器>
The code is very simple and perfectly works on API >= 3.0, but if I started at API 2.3 I'm getting the problem - Google send only registration events:
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
//sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
//sendNotification("Deleted messages on server: " + extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// we are here if API >= 3.0
}
else if (isRegistrationIntent(intent)) {
// WE ARE HERE IF API 2.3 <----- BUG
}
}
// Release the wake lock provided by the WakefulBroadcastReceiver.
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
Registration is successful. But after that, my Sony Хperia (API 2.3) get only the registration's events: from another device sent GCM-message, but Xperia receive a notification of registration. Magic; (
Does anyone know the possible causes?
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fenix14"
android:versionCode="2"
android:versionName="DVA" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM settings -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.fenix14.utils.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.fenix14.utils.permission.C2D_MESSAGE" />
<!-- /GCM settings -->
<application
android:allowBackup="true"
android:name="com.fenix14.utils.FenixApp"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/FenixActionBarTheme" >
<!-- GCM settings -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<receiver
android:name="com.fenix14.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.fenix14.gcm" />
</intent-filter>
</receiver>
<service android:name="com.fenix14.gcm.GcmIntentService" />
<!-- /GCM settings -->
<activity
android:name="com.fenix14.entry.MainActivity"
android:theme="@style/FenixActionBar.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Your manifest has many inconsistencies :
package="com.fenix14"
<permission android:name="com.fenix14.utils.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.fenix14.utils.permission.C2D_MESSAGE" />
<receiver
android:name="com.fenix14.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.fenix14.gcm" />
</intent-filter>
</receiver>
You should use the same package name in all the GCM relevant places, so it should be :
package="com.fenix14"
<permission android:name="com.fenix14.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.fenix14.permission.C2D_MESSAGE" />
<receiver
android:name="com.fenix14.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.fenix14" />
</intent-filter>
</receiver>
这篇关于API 2.3 Google云端通讯仅获得注册事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!