简体   繁体   English

Android Parse Push Notification不起作用-“过时的设备”

[英]Android Parse Push Notification not working - “Outdated device”

After following this tutorial: https://parse.com/apps/quickstart#parse_push/android/native/existing 在遵循了本教程之后: https : //parse.com/apps/quickstart#parse_push/android/native/existing

and this one: http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/ 而这个: http : //www.androidhive.info/2015/06/android-push-notifications-using-parse-com/

and reading all the related questions on stackoverflow, I still can't figure out why Parse is telling me the devices are all outdated. 并阅读了关于stackoverflow的所有相关问题,我仍然不明白为什么Parse告诉我所有设备都已过时。

Here's the Manifest: 这是清单:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.GET_TASKS"/>

<permission android:protectionLevel="signature"
    android:name="com.myPackage.myApp.C2D_MESSAGE" />
<uses-permission android:name="com.myPackage.myApp.C2D_MESSAGE" />

... ...

<service android:name="com.parse.PushService"/>
    <receiver android:name=".Receiver.CustomPushReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <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.myPackage.myApp"/>
        </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>
    <meta-data android:name="com.parse.push.gcm_sender_id"
        android:value="id:myAppAndroidUser" />

And the Application looks like this: 应用程序看起来像这样:

// Parse config
    Parse.enableLocalDatastore(this);
    ParseCrashReporting.enable(this);
    Parse.initialize(this, "[app key]", "[client key]");
    ParseFacebookUtils.initialize(this);

    ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
    ArrayList<String> channels = new ArrayList<>();
    channels.add("global");

    PushService.setDefaultPushCallback(getApplicationContext(), MainActivity.class);
    ParsePush.subscribeInBackground("", new SaveCallback() {
        @Override
        public void done(ParseException e) {
            Log.d("Application", "Subscribed to ParsePush");
        }
    });

    parseInstallation.put("channels", channels);
    parseInstallation.saveInBackground();

I'm using Lollipop and Parse 1.9.3 我正在使用Lollipop和Parse 1.9.3

I even see the log statement "Subscribed to ParsePush," so I must be close... 我什至看到日志语句“ Subscribed to ParsePush”,所以我必须亲近...

OK, I think I finally figured it out, since I got a notification to go through successfully from Parse (FINALLY!) I replaced the custom receiver (that was part of one of the tutorials) with this: 好的,我想我终于明白了,因为我收到了Parse通知成功通过的通知(最终完成!),我用以下方法替换了自定义接收器(这是其中一个教程的一部分):

<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>

Not totally sure why that worked, but that's what did it, I think. 不能完全确定为什么这样做有效,但是我认为那是这样做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM