4
我正在嘗試執行一些操作,如暫停音樂,在按鈕上單擊Android中的自定義通知播放音樂。 目前,我做這樣,在按鈕上執行操作在自定義通知中單擊:Android
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, "Custom Notification", when);
NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.layout);
contentView.setTextViewText(R.id.textView1, "Custom notification");
contentView.setOnClickPendingIntent(R.id.button1, pIntent);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound
mNotificationManager.notify(1, notification);
但是這一次帶我到另一個活動。 無論如何要對同一活動實施通知操作。
例如..比方說,我養notifcation,並在其上的用戶按,然後而不是帶我去一些活動,它在我的當前活動/服務
我已經給了一個答案對同一給定鏈路上http://stackoverflow.com/questions/11270898/how-to-execute-a-method-by-clicking-a-notification/11271367#11271367 –