2015-12-28 44 views
0

我剛剛更新了最新的解析SDK(1.11.0),現在我沒有收到推送通知。我能夠註冊成功,可以說,我的「開發者」通道已認購但是把永不會收到解析網站上看到,我得到這個錯誤:Android解析推送通知不工作 - 過時的設備

PPNS - Outdated device - The records on this installation are outdated, the user might have uninstalled the app.

可有人請看看我的代碼看看你是否注意到有什麼不對?

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清單:

<?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; 
} 

}

回答

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> 

希望它有效。

+0

非常感謝。這解決了它!我試圖讓你高興,但我認爲我沒有足夠的積分來做到這一點呢?我還是新的。謝謝! – chelsiamia