当应用程序在marshmallow中关闭时,未收到推送通知。当我的应用程序打开其工作正常时。在棒棒糖工作中,罚款对于app打开或关闭无关紧要。
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
我在清单文件中给予许可。
答案 0 :(得分:0)
除了这些权限之外,您还需要在AndroidManifest.xml文件中使用正确的intent过滤器指定BroadcastReceiver:
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.yourapp" />
</intent-filter>
</receiver>
然后在你的BroadcastReceiver中显示一条通知:
public class GcmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// Show Notification
}
setResultCode(Activity.RESULT_OK);
}
}