我创造了这个Android的通知成功,但是我想激活后,触摸我的主要活动。
I created this Android notification successfully, however I want to activate my main activity upon touch.
下面是我的code。
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但我仍然无法启动我的活动。
I have checked my work here but I was still unable to start my activity.
有什么建议?
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, notificationIntent, 0);
使用
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
上一篇:AutoCompleteTextView适配器没有设置适配器、AutoCompleteTextView
下一篇:如何设置三种不同的TEXTSIZE在android的单一的TextView三种、如何设置、不同、TextView