下面找到清单文件,他们的GCM推送通知类配置有什么问题吗?
在安卓设备上根本没有收到通知,但苹果设备会收到通知
package="ac.iec"
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission
android:name="ac.iec.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="ac.iec.permission.C2D_MESSAGE"/>
<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.RECEIVE"/>
<category android:name="ac.iec"/>
</intent-filter>
</receiver>
<service
android:name=".pushnotification.GCMIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<service
android:name=".pushnotification.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
你错过了一些像这样user permisssion
和reciver
设置。
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
此权限设置
<permission
android:name="your package name.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
此用户权限
<uses-permission android:name="your package.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
此代码设置在application
端。
<!-- GCM Receiver -->
<!-- this package name set your broadcast receiver class -->
<receiver
android:name="package name .GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="main package name" />
</intent-filter>
</receiver>
在清单文件中尝试此代码。谢谢。
<receiver>
标签和<services>
标签应该在<application>
标签中。
或者,如果您支持 4.4 之前的版本,则应添加注册操作。https://developers.google.com/cloud-messaging/android/client
如果要支持 4.4 之前的 KitKat 设备,请添加以下内容 对接收方的意图过滤器声明的操作: