Android Parse推送通知无法正常工作 - 过时的设备

时间:2015-12-28 19:00:46

标签: android parse-platform push-notification

我刚刚更新了最新的Parse SDK(1.11.0),现在我没有收到推送通知。我能够成功注册,并且可以在解析网站上看到我的“开发者”频道已经订阅但推送永远不会被发送,我收到此错误:

  

PPNS - 过时的设备 - 此安装的记录是   过时,用户可能已经卸载了应用程序。

有人可以看看我的代码,看看你是否发现任何不正确的内容?

public class LSIApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this, "********", "********");
        ParseInstallation.getCurrentInstallation().saveInBackground();
        ParsePush.subscribeInBackground("developer", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });
        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    }
}`

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>

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

<permission
    android:name="${applicationId}.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission android:name="${applicationId}.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>

<permission android:protectionLevel="signature"
            android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:name=".LSIApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="********" />

    <service android:name="com.parse.PushService" />
    <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=".startup.PushBroadcastReceiver"
              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>
</application>

注意:$ {applicationId}是'com.broker.schlisimobile.dev'和/或'com.broker.schlisimobile',具体取决于它是生产版还是开发版。

这是我的自定义PushBroadcastReceiver类:

public class PushBroadcastReceiver extends ParsePushBroadcastReceiver {
@Override
protected void onPushOpen(Context context, Intent intent) {
    if ( storyJSONExists(intent) ) {
        if (!DataController.getInstance().getCurrentUser().isGuestUser() ) {
            Intent i = new Intent(context, PushLoadingActivity.class);
            i.putExtras(intent.getExtras());
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        } else {
            Intent i = new Intent(context, HomeActivity.class);
            i.putExtra("promptForLogin", true);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
            context.startActivity(i);
        }
    } else {
        Intent i = new Intent(context, HomeActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.putExtras(i);
        context.startActivity(i);
    }
}

private boolean storyJSONExists(Intent intent) {
    try {
        String jsonString = intent.getExtras().getString("com.parse.Data");
        JSONObject json = new JSONObject(jsonString);
        if ( json.has("postID") ) {
            return true;
        }
    } catch (JSONException jsonE) {
        jsonE.printStackTrace();
    }
    return false;
}

}

1 个答案:

答案 0 :(得分:3)

在您的manifest.xml注释/删除下面的代码

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

然后在manifest.xml中添加以下代码

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

  <!--IMPORTANT: Change "com.parse.starter" to match your app's package name.-->

        <category android:name="your_application_id" />
   </intent-filter>
 </receiver>
希望它有效。