Android的 - 开放解析推送通知崩溃 [英] Android - Parse push notification crashes on open
问题描述
我已经建立了解析推送通知,我有我的应用程序崩溃当我试图打开它,现在我发现在我制作一个新的Java类并覆盖工作 onPushOpen
是这样的:
I have set up parse push notifications and I had my app crash when I tried to open it, now I found a work around my making a new java class and overriding onPushOpen
like this:
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);
}
}
但为了仍然收到推送通知我还需要这代preciated方法在我MyApplication.java类 PushService.setDefaultPushCallback(这一点,MainActivity.class);
我怎么能摆脱这种德preciated方法我已经看过这个问题,在这里我得到了一些帮助,但它并没有回答这部分对德preciated方法。 <一href=\"http://stackoverflow.com/questions/26154855/exception-when-opening-parse-push-notification\">Exception打开解析推送通知时。
How could I get rid of this depreciated method I have looked at this question where I got some help but it did not answer this part about the depreciated method. Exception when opening Parse push notification.
我在想,也许这种方法可能超过缠身,但林不知道,如果它敏锐地处理recvieving推或多个处理它已经收到后推?
I was thinking that maybe this method could be over ridden but Im not sure if it acutely handles recvieving the push or more handles the push after it has been received?
@Override
public void onPushReceive(final Context c, Intent i) {
// Handle the received push
}
感谢您提前帮助。
推荐答案
您是继承 ParsePushBroadcastReceiver
。
然后在清单
<receiver
android:name=".Receiver " // your broadcastreceiver
android:exported="false" >
<intent-filter>
// youtr actions
</intent-filter>
</receiver>
在广播接收器
public class Receiver extends ParseBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
extras = intent.getExtras();
if(intent.hasExtra("com.parse.Data"))
{
try
{
json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
int notificationtype = json.getInt("notificationtype"); // this is send on the sender side
switch(notificationtype)
{
case 1:
// show your custom notification. Refer android notification guide
break;
case 2:
//rest of the code
请注意:如果有一个警告或标题在推规定,然后通知正在使用构造的GetNotification
。因此,没有警报和标题在发送方。
Note : If either "alert" or "title" are specified in the push, then a Notification is constructed using getNotification
. So no alert and title on the sender side.
阅读管理推送生命周期@
Read Managing Push Lifecycle @
https://www.parse.com/docs/push_guide#receiving/Android
参考
的https://www.parse.com/questions/how-sup$p$pss-push-notification-from-being-displayed
这篇关于Android的 - 开放解析推送通知崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!