我創建了一個android app using webview
。如果我的WordPress博客上有任何新帖子,想要在手機上收到新帖子的通知?
我想向我的用戶(誰安裝了我的android應用程序)顯示新博客帖子的通知。
當用戶點擊該通知時,網址應該在webview中打開。
我想這樣的教程。
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);
您的應用包含Web視圖活動的權利。 –
是的,我的應用包含我的博客鏈接。通過使用'webview'我在手機上顯示 – Neo