【发布时间】:2012-11-22 21:28:15
【问题描述】:
我的应用中有一条通知,其中包含以下代码:
//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);
}
我的通知触发得很好,但我的问题是,当我在通知中心点击通知时,它并没有启动我的应用程序。
基本上,点击我的通知后,什么都没有发生! 我应该怎么做才能在单击我的通知后开始我的主要活动。 谢谢。
【问题讨论】:
-
试试this
-
在
Notification notification = new Notification(icon, tickerText, when);之前移动Context context = getApplicationContext();也许你没有传递正确的上下文来启动 Activity -
4 年多前...从那天起你经历了多么漫长的旅程 :) 但 android 通知没有任何变化 ;)
-
@HamedGh 差不多 5 年前! :)))
-
@Reza_Rg 是 7 年前。我也有同样的问题!
标签: android notifications