onclick获取从数据库android生成的本地通知的内容

时间:2016-06-14 09:37:44

标签: android database notifications local

我通过匹配数据库中的数据生成了多个本地通知。 现在,我希望点击通知,然后点击特定产品。

代码:----------

for (int i=0;i < alertList.size();i++) {
                Random random = new Random();
                int m = random.nextInt(9999 - 1000) + 1000;
                msg=alertList.get(i).getProf_name()+" have to take "+alertList.get(i).getMed_name()+"                                                                                          ;"+alertList.get(i).getMed_id();
                Log.d("MediMSg",""+msg);
                Log.d("MediMSg",""+msg);
                Intent notificationIntent = new Intent(context, MedicineNotificationActivity.class);
                notificationIntent.putExtra("pushmsg",msg);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
                stackBuilder.addParentStack(MedicineNotificationActivity.class);
                stackBuilder.addNextIntent(notificationIntent);
                PendingIntent pendingIntent = stackBuilder.getPendingIntent(100, PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
                Notification notification = builder.setContentTitle("Test")
                        .setContentText(msg)
                        .setTicker("Notification from Test")
                        .setSmallIcon(getNotificationIcon())
                        .setPriority(Notification.PRIORITY_MAX)
                        .setAutoCancel(true)
                        .setColor(0x0091ea)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentIntent(pendingIntent).build();

                NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(m,notification);
                Log.d("Random",""+m);
            }

0 个答案:

没有答案