0
我想打電話給活動NotificationReceiver
,當我點擊一個android通知。通知OnClick事件
通知已經正確顯示,但是當我點擊通知時沒有任何反應。
下面是通知代碼:
private void notification_anzeigen2(){
Log.d("Test2", "Test2 ");
Intent intent = new Intent(this, NotificationReceiver.class);
intent.putExtra("NotiClick",true);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, Intent.FILL_IN_ACTION);
Notification n = new Notification.Builder(this).setContentTitle("GestureAnyWhere Hintergrundservice")
.setContentText("Bitte klicken, um den Hintergrundservice zu beenden")
.setContentIntent(pIntent)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.build();
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, n);
Log.d("Test3", "Test3 ");
}
這裏是活動:
public class NotificationReceiver extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null)
{
Log.d("Test4", "Test4");
}
else if (extras.getBoolean("NotiClick"))
{
Log.d("Test5", "Test5");
stopService(new Intent(getApplicationContext(), HintergrundService.class));
}
}
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
}
非常感謝。
您是否在Manifest中註冊了NotificationReceiver活動? (順便說一下,NotificationReceiver不是一個活動的好名字,因爲接收者通常意味着Android中的其他東西)。 –