- 我在OnReceive()方法中实现了广播接收器方法编写通知管理器代码。
- 通知中正在播放自定义铃声。在通知的点击声停止
问题 我做不到的事情,如果应用程序打开小于告知不会在通知栏来显示。预计通知我会更新我的视图的用户界面[即。我会告诉STOP按钮停止铃声。]Android:通知管理器只在应用程序关闭时通知
通知代码
public void sendNotification(Context context, String title, String message, String fileName)
{
final String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager notificationManager = (NotificationManager)context.getSystemService(ns);
final Notification notification = new Notification(R.drawable.ic_launcher, context.getString(R.string.SalahClock), System.currentTimeMillis());
Intent intent = new Intent(context, Main.class);
intent.putExtra("isAlarmPlaying", true);
//Pending event to open our Application Screen when this notification is clicked
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent , 0);
notification.setLatestEventInfo(context, title, message, contentIntent);
notification.sound = Uri.parse("android.resource://path..");
notification.flags |= Notification.FLAG_INSISTENT;
notificationManager.notify(1, notification);
}
在ReCevie
public void onReceive(Context context, Intent intent) {
serviceHandler = new Handler(context);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Salah");
wl.acquire();
serviceHandler.sendNotification(context, "", "", "");
wl.release();
}
谢谢
Salik
我不明白你的问题是:“这是怎么回事,怎么解决这个问题”,或者“这是我想要的,怎么做?” – auval 2013-05-13 07:17:24
通知当应用程序处于活动状态[或打开]时也会打开。通知应该只在应用程序关闭时显示。 – nalaiqChughtai 2013-05-13 07:26:38
如果您有更好的解决方案,请在下面张贴并接受您自己的解决方案。如果我的回答是最好的,不要忘记接受它。 – auval 2013-07-18 06:44:54