终止的应用通知点击意图putExtra方法不起作用 [英] Killed app notification click intent putExtra method not working

查看:76
本文介绍了终止的应用通知点击意图putExtra方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,当该应用程序被终止时,intent.putExtra无法正常工作.唤醒和运行模式均有效.我使用的是Firebase消息传递服务getData()方法,有待处理的意图.

I have a problem intent.putExtra is not working when the app is killed. Wake up and running mode all works. I use firebase messaging service, getData() method, pending intent.

private PendingIntent getPendingIntent(int newsID) {
    Intent intent = new Intent(this, DetailedNewsActivity.class);
    intent.putExtra("newsID", newsID);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
    // All the parents of SecondActivity will be added to task stack.
    stackBuilder.addNextIntentWithParentStack(intent);

    //PendingIntent pendingIntent = PendingIntent.getActivity(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(100, PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
}

推荐答案

先检查该数据,然后再使用

Check that data first then use that

// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
   try {
      JSONObject json = new JSONObject("{\"data\":"+remoteMessage.getData().toString()+"}");
      //decode your json data and use that
    } catch (Exception e) {
       Log.e(TAG, "Exception: " + e.getMessage());
    }
}

// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
    String stingMessage = remoteMessage.getNotification().getBody();
    //show the message string as notification or as your want
}

显示通知并添加未决意图

To show notification and add pending intent

Intent myintent = new Intent(this, YourActivityWantToL.class);
    myintent.putExtra("message", stingMessage);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, myintent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(TAG)
                    .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg))
                    .setContentText(stingMessage);

    mBuilder.setContentIntent(contentIntent);

但是,如果您要在26或更高版本上定位和运行应用,则必须使用通知频道

but if you are targeting and running app on 26 or higher you have to use notification channel

这篇关于终止的应用通知点击意图putExtra方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆