问题 我没有做到, 如果应用程序打开,通知栏将不会显示通知栏。 期待通知我将更新我的视图的UI [即。我将显示STOP按钮以停止铃声。]
通知代码
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
答案 0 :(得分:3)
您可以使用静态变量:
public static boolean sIsActive = false;
项目中的任何位置,并将其设置为true
上的onResume()
活动false
以及活动onPause()
上的if (MyClass.sIsActive) { return; }
。
在接收器中,您可以查看:
{{1}}
如果未激活,请继续通知。