java - 点击推送消息后访问推送通知内容(Android)

标签 java android notifications google-cloud-messaging push

我有一个 Android 应用程序,它正在接收推送消息。

如果用户单击推送消息,则会调用 Activity GoToNotification。 到目前为止,这是有效的。

但是如何获取推送消息的内容呢? Bundle.extra? 我正在尝试对推送消息的某些内容使用react,但 bundle 额外内容始终为空。

这是我到目前为止的代码:

private void sendNotification(String msg, Bundle extras) {
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, GoToNotification.class), 0);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("Warning")
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(msg))
                    .setAutoCancel(true)
                    .setWhen(System.currentTimeMillis())
                    .setExtras(extras)
                    .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}


public class GoToNotification extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle extras = this.getIntent().getExtras();
        if (extras != null) {
            System.out.println(extras.toString());
        } else {
            System.out.println("extras is null");
        }
    }
}

最佳答案

Intent notificationIntent = new Intent(context, SampleActivity.class);
notificationIntent.putExtra("EXTRA_ID", "ur data");

在你的 Activity 中

if (extras != null) {
 ID = extras.getString("EXTRA_ID");
}

关于java - 点击推送消息后访问推送通知内容(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33166842/

相关文章:

android - 单击通知栏时复制应用程序

java - 关于数组列表中已定义的槽

java - UnsatisfiedLinkError: java.library.path 中没有 j3dcore-ogl

java - 列出android中下载目录中的文件

android - 如何正确设置 ZXingScannerView 的选项?

iphone - 将 NSData 序列化为十六进制字符串的最佳方法

java - Oracle 不同与 java (cqengine/set) : whose leads to better performances?

java - ReSTLet:所有 500 个错误的日志堆栈跟踪

android - 奥利奥 : Broadcast receiver Not working

IOS 推送通知 smartface 4.3 注册和远程 token