3
这是我的清单文件定制GcmListenerService不工作
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.customapp" >
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM: keep device awake while receiving a notification -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- GCM: receive push notifications -->
<permission android:name="be.customapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="be.customapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Meta data -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key"/>
<!-- Activities -->
<activity
android:name=".ui.activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Services -->
<service
android:exported="false"
android:name=".services.gcm.MyGcmListenerService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:exported="false"
android:name=".services.gcm.GcmRegisterService"/>
<service
android:name=".services.gcm.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!-- Broadcastreceivers -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="be.prior_it.evapp" />
</intent-filter>
</receiver>
</application>
</manifest>
这是获取服务/注册我的注册ID;
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
MyGcmListenerService;
public class MyGcmListenerService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
super.onMessageReceived(from, data);
Log.i(Constants.LOG_TAG, "Got GCM message " + data.getString("message"));
}
}
服务器使用PushJack并发送到注册ID。我可以看到服务器可以发送消息,我可以获取我的注册ID并将其注册到我们的服务器,但onMessageReceived永远不会被调用...我还使用网站上的链接创建了google-services.json,所以那也应该没问题。
欢迎任何或所有想法。
您是否订阅了您的通知发送的主题?或者你是否发送到特定设备的令牌?上面的代码的信息太少(例如,获取注册ID的函数头是什么?你的GCMListenerServices的写法如何? – Elye
服务器发送到在向GCM注册设备的服务中发送给它的特定令牌。 Gcm listener现在只会记录Bundle,如果这个函数被调用,那永远不会发生。你用什么函数头来取得reg ID? – Pieterjan
你有开启你的互联网权限吗?''' –
Elye