解析 GCM 推送通知不适用于 Android 6.0 Marshmallow Developer Preview 3

Parse GCM push notifications not working on Android 6.0 Marshmallow Developer Preview 3

我已经在我的 AndroidManifest.xml 中注册了必要的权限、服务和广播接收器,并且我在 Android M 之前的设备上运行了 Parse 推送通知。我在 Nexus 5 上的 Android 6.0 Marshmallow Developer Preview 3 运行 中收到一个错误(在下面发布)。用户注册成功,我可以在 [=29= 上的 Parse 仪表板中查看它],但 pushTypedeviceLastTokenModifiedundefined。考虑到这在 Pre Android M 设备上运行良好,我不禁认为这是 Parse SDK 的问题。 Android M 的权限更改可能是一个问题,除了我请求的 none 权限属于要求用户授予它的类别。

这是错误::

08-30 19:29:19.671  11848-11848/com.example.app V/com.parse.ManifestInfo﹕ Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root <manifest> element:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.richardlucasapps.eaglescribe.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.richardlucasapps.eaglescribe.permission.C2D_MESSAGE" />
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.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.richardlucasapps.eaglescribe" />
</intent-filter>
</receiver>
08-30 19:29:19.671  11848-11848/com.example.app V/com.parse.ManifestInfo﹕ Using none for push.

以下是我如何初始化 Parse 并将其设置为推送通知:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
        Parse.initialize(this, applicationId, clientId);

        ParseUser.enableAutomaticUser();
        ParseUser.getCurrentUser().increment("RunCount");
        ParseUser.getCurrentUser().saveInBackground();

        ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
        parseInstallation.put("user", ParseUser.getCurrentUser());
        parseInstallation.saveInBackground()
    }
}

这是我的 AndroidManifest.xml 文件的精简版:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app” >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!--
  IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
  to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission
    android:name="com.example.app.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />

<application
    android:name=".global.MyApplication">
    <!-- For Parse Notification Push Service -->
    <service android:name="com.parse.PushService" />

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.parse.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.example.app” />
        </intent-filter>
    </receiver>
</application>

更新您在项目中使用的 Parse 库。我使用的是 1.9.4 并已更新到 Parse 1.10.1,现在我的 Android Marshmallow 设备已成功注册并接收推送通知。

Grab the most up to date Parse library here.