Android Parse 推送通知不起作用 - 过时的设备
Posted
技术标签:
【中文标题】Android Parse 推送通知不起作用 - 过时的设备【英文标题】:Android Parse Push Notifications Not Working - Outdated Device 【发布时间】:2015-12-28 19:00:45 【问题描述】:我刚刚更新了最新的 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 清单:
<?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】:在您的 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>
希望它有效。
【讨论】:
非常感谢。那解决了它!我试图为你投票,但我认为我还没有足够的积分来投票?我还是新人。谢谢!以上是关于Android Parse 推送通知不起作用 - 过时的设备的主要内容,如果未能解决你的问题,请参考以下文章
Android 解析推送通知和新 GCM 生成错误的设备令牌并解析推送通知不起作用