我创建了一个android app using webview
。
我想向我的用户(已安装我的Android应用)显示新博客帖子的通知。
当用户点击该通知时,应在webview中打开Url。
我试过这个教程。
mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
int notifyID = 1;
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle("New Message")
.setContentText("You've received new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
// Start of a loop that processes data and then notifies the user
...
mNotifyBuilder.setContentText(currentText)
.setNumber(++numMessages);
// Because the ID remains unchanged, the existing notification is
// updated.
mNotificationManager.notify(
notifyID,
mNotifyBuilder.build());
但我是新手,这根本不起作用
还在protected void onCreate(Bundle savedInstanceState) {
Intent notificationIntent = new Intent(context, yourwebviewactivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new NotificationCompat.Builder(context)
.setSmallIcon(icon_small)
.setTicker("ticker message")
.setLargeIcon(largeIcon)
.setWhen(System.currentTimeMillis())
.setContentTitle("title")
.setContentText("message")
.setContentIntent(contentIntent)
//At most three action buttons can be added
.setAutoCancel(true).build();
notificationManager.notify(notifyID, noti);
答案 0 :(得分:2)
您需要将Notification Intent Activity
设置为:
Intent notificationIntent = new Intent(context, yourwebviewactivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new NotificationCompat.Builder(context)
.setSmallIcon(icon_small)
.setTicker("ticker message")
.setLargeIcon(largeIcon)
.setWhen(System.currentTimeMillis())
.setContentTitle("title")
.setContentText("message")
.setContentIntent(contentIntent)
//At most three action buttons can be added
.setAutoCancel(true).build();
notificationManager.notify(notifyID, noti);
不要忘记在Activity
manifest.xml
有关更多信息,请访问:http://developer.android.com/guide/topics/ui/notifiers/notifications.html