我的应用程序中有一个包含以下代码的通知:
//Notification Start
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.n1;
CharSequence tickerText = "Call Blocker";
long when = System.currentTimeMillis(); //now
Notification notification = new Notification(icon, tickerText, when);
Intent notificationIntent = new Intent(context, Main.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Context context = getApplicationContext();
CharSequence title = "Call Blocker";
text = "Calls will be blocked while driving";
notification.setLatestEventInfo(context, title, text, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notificationManager.notify(1, notification);
}
我的通知可以正常触发,但问题在于,当我在通知中心点击通知时,它没有启动我的应用程序。
基本上,在点击我的通知后什么也没发生! 我应该怎么做,才能让点击通知后启动我的主活动。 谢谢。
Context context = getApplicationContext();
移动到Notification notification = new Notification(icon, tickerText, when);
之前,也许您没有传递正确的上下文来启动 Activity。 - ρяσѕρєя K