[英]Android - Parse push notification crashes on open
我已經設置了解析推送通知,嘗試打開它時我的應用程序崩潰了,現在我找到了一個解決方法,可以制作一個新的Java類並像這樣覆蓋onPushOpen
:
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);
}
}
但是為了仍然接收推送通知,我仍需要在MyApplication.java類PushService.setDefaultPushCallback(this, MainActivity.class);
此折舊方法PushService.setDefaultPushCallback(this, MainActivity.class);
我如何擺脫這種折舊方法,我在這個問題上得到了一些幫助,但是卻沒有回答有關折舊方法的這一部分。 打開“解析”推送通知時發生異常 。
我當時想也許可以改寫這種方法,但是我不確定它是敏銳地處理推送內容還是更多地處理推送內容?
@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>
在BroadCastReceiver中
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
注意:如果在推送中指定了“ alert”或“ title”,則使用getNotification
構造Notification。 因此,發件人一側沒有警報和標題。
閱讀管理推送生命周期@
https://www.parse.com/docs/push_guide#receiving/Android
參考
https://www.parse.com/questions/how-suppress-push-notification-from-being-displayed
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.