我在我的应用程序中配置了 Parse API,除推送通知外,一切正常。我试图从网站发送它们,但它们没有到达应用程序。 我做了所有写在 documentation 中的事情,但我无法接收通知推送。
我能够收到一个,但当我按下它时,应用程序崩溃了。现在我试图改变一些东西,但即使逆转我也无法再收到它们。我该如何解决我的问题?
编辑:由于一些用户可能感兴趣,这里是我用于推送通知的部分代码:
主类(虽然不是 MainActivity):
public class InstantsApplication extends Application {
public void onCreate() {
super.onCreate();
// Hidden
Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", 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);
}
}
}
}
AndroidManifest(这里没有包括权限,相信我,我已经放好了):
<!-- PARSE -->
<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.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.tutorials.pushnotifications" to match your app's package name.
-->
<!-- I have hidden package name root for this question -->
<category android:name="com.xxxxxxxx.instants" />
</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>
</application>
最佳答案
我之前遇到过这个问题,那是因为你使用了最新的 Parse api。 您只需要进行一些更改。
首先,要修复由从 Parse 后端发出推送直接导致的错误,您需要在 Manifest 中为 Parse 推送声明一个通知图标。
<meta-data android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_launcher"/>
在关闭应用程序标签之前使用。
现在从后端发出另一个推送将如您所料给您一个推送通知。到目前为止,一切都很好。单击推送将导致应用程序再次崩溃。要解决此问题,您需要删除现已弃用的调用 PushService.setDefaultPushCallback(...)
并添加您自己的 Receiver 类。我在 *.util 包中按以下方式执行此操作:
public class Receiver extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
接下来,将默认的 Parse 接收器更改为刚创建的那个:- 转到您的 list 文件。
<receiver
android:name="your.package.name.utils.Receiver"
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>
关于java - 我无法在应用程序中接收来自 Parse 的推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27367362/