gpt4 book ai didi

每次通知点击 Android 通知 PendingIntent 打开 Activity

转载 作者:行者123 更新时间:2023-11-29 16:06:15 25 4
gpt4 key购买 nike

我目前正在为我的应用做一些通知。现在我已经成功创建了一个通知,但问题是我的每个通知都不会在点击时传递不同的额外信息。

发生的事情是,我只有一个循环,每个循环都调用 createNotification 方法,而且我还为通知分配了不同的 ID,以便通知出现在不同的堆栈中。

这是我的代码:

private void createNotification(String record_name, String file_path, String status, int id) {
/*must pass:
* record_name, (get the record name in DB using the id create a new query method)
* record_status, (simple part just match if equivalent to ready to download for the JSON data then show notif if true)
* record_path *full path* (this one can be get using the record name itself add the path and extension name)*/

/*this will jump from the current activity into the target activity class just do some workarounds here*/
Intent intent = new Intent(this, RecordEditActivity.class);
intent.putExtra("record_name", record_name);
intent.putExtra("record_path", file_path);
intent.putExtra("record_status", status);
PendingIntent pIntent = PendingIntent.getActivity(this,0, intent, 0);


/*build the notification here this is only supported for API 11. Since we've targeted API 11 there will be no problem on this*/
NotificationCompat.Builder notify = new NotificationCompat.Builder(this)
.setContentTitle(record_name + " is ready for download")
.setContentText("Click to view or download recording")
.setAutoCancel(true)
.setSmallIcon(R.drawable.notif_icon)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher))
.setTicker("Echo: your file is ready for download")
.setContentIntent(pIntent);


NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

if(Build.VERSION.SDK_INT<16){
/*build notification for HoneyComb to ICS*/
notificationManager.notify(id, notify.getNotification());
}if(Build.VERSION.SDK_INT>15){
/*Notification for Jellybean and above*/
notificationManager.notify(id, notify.build());
}

}

我认为问题出在 PendingIntent 部分,因为我不知道我应该为此使用哪些标志,但我不太确定。

最佳答案

明白了!我需要为我的 pendingIntent 分配一个 ID requestCode 我所做的是分配我用于 notificationManager 的相同 ID。

更多信息 here .

关于每次通知点击 Android 通知 PendingIntent 打开 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18094791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com