来自数据库的 android 中的本地通知
Local notification in android from database
我的要求是在当前时间与 database.But 中的值匹配时生成本地通知现在的问题是当我单击通知时它应该将我带到使用该产品的特定产品详细信息id.
我已经生成了通知,但如何才能将产品 title/id 带到产品详细信息页面。
代码----------------
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);
}
当您生成通知时,但 Intent 中的产品 title/id 作为附加项。然后在您的 activity 中,通过单击通知启动。您可以访问这些附加功能。
如果你有多个id,你可以在循环外创建一个数组,像这样:
int[] ids = new int[alertList.size()];
然后在循环中,迭代并为每个索引设置 id。
for (int i=0;i < alertList.size();i++) {
ids[i] = YOUR_ID;
//OTHER Code
}
最后,像这样补充:
notificationIntent.putExtra("ids", ids);
我的要求是在当前时间与 database.But 中的值匹配时生成本地通知现在的问题是当我单击通知时它应该将我带到使用该产品的特定产品详细信息id.
我已经生成了通知,但如何才能将产品 title/id 带到产品详细信息页面。
代码----------------
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);
}
当您生成通知时,但 Intent 中的产品 title/id 作为附加项。然后在您的 activity 中,通过单击通知启动。您可以访问这些附加功能。
如果你有多个id,你可以在循环外创建一个数组,像这样:
int[] ids = new int[alertList.size()];
然后在循环中,迭代并为每个索引设置 id。
for (int i=0;i < alertList.size();i++) {
ids[i] = YOUR_ID;
//OTHER Code
}
最后,像这样补充:
notificationIntent.putExtra("ids", ids);