- 我实现了一个广播接收器,在 OnReceive() 方法中编写了通知管理器代码。
- 自定义铃声正在通知中播放。单击通知时声音停止
我没有做的问题,如果应用程序打开,通知将不会显示在通知栏上。期待通知我将更新我的视图的 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);
}
在接收
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();
}
谢谢,
萨利克