我實際上在Android中使用notifications
。在Android中點擊通知後在應用中添加新視圖?
做我的應用測試,我跟着the guide on android.developer。
我創建了我的通知,它效果很好。當我點擊它時,它會從通知選項卡中刪除通知,並在我進入我的活動之後。
這裏是我用來做代碼:
public void createSimpleNotification() {
NotificationCompat.Builder mNotifBuilder = new NotificationCompat.Builder(this.getApplicationContext())
.setSmallIcon(R.drawable.ic_notif).setContentTitle("Simple notif").setContentText("Welcome on our app, click here");
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder mStackBuilder = TaskStackBuilder.create(this.getApplicationContext());
mStackBuilder.addParentStack(MainActivity.class);
mStackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = mStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mNotifBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifManager.notify(0, mNotifBuilder.build());
}
我只有我的MainActivity
和Button
。當我點擊按鈕時,通知出現,我點擊通知,我回到我的MainActivity。
這裏是我的問題:
我想點擊的通知後,更新我MainActivity UI
。點擊通知後,我需要創建一個Dialog
誰顯示通知的文本。
如何修改我的Activity
和點擊的通知後添加新的View
?
處理它我同意你的意見,但我如何訪問我的查看onClick on通知? – Androzr
您在活動中創建視圖。只要將其設爲靜態類變量即可。那麼你可以通過'ActivityWithView.myNotificationView'來訪問它,例如 – PKlumpp
是的,我明白你說什麼,但我怎麼知道通知是否被點擊? – Androzr