2015-05-17 5 views
0

Я создал это уведомление для Android, но я хочу активировать свою основную деятельность прикосновением.Уведомление не активировало свою деятельность

Вот мой код.

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); 
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // only needed for activity activation 

PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, notificationIntent, 0); 

Notification notification = new Notification(R.drawable.floating2, "Click to start launcher",System.currentTimeMillis()); 
notification.setLatestEventInfo(getApplicationContext(), "Start launcher" , "Click to start launcher", pendingIntent); 
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT; 

NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); 

notificationManager.notify(ID_NOTIFICATION,notification); 

Я проверил мою работу here, но я все еще не мог начать свою деятельность.

Любые предложения?

+0

является он показывает какую-либо ошибку? –

ответ

2

Вместо

PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, notificationIntent, 0); 

использование

PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); 
Смежные вопросы