Android 按音量按钮时停止通知声音

Android 按音量按钮时停止通知声音,android,notifications,alarm,Android,Notifications,Alarm,我使用附带的代码设置警报。除了一件事之外,这很好用。如果手机已关机且通知已启动,则不能像按闹钟一样按音量按钮停止通知 有谁知道这是怎么处理的,或者我在哪里可以找到这个 多谢各位 public class OneShotAlarm extends BroadcastReceiver { private static final int NOTIFICATION_ID = 0; @Override public void onReceive(Context context, Intent int

我使用附带的代码设置警报。除了一件事之外,这很好用。如果手机已关机且通知已启动,则不能像按闹钟一样按音量按钮停止通知

有谁知道这是怎么处理的,或者我在哪里可以找到这个

多谢各位

public class OneShotAlarm extends BroadcastReceiver {

private static final int NOTIFICATION_ID = 0;

@Override
public void onReceive(Context context, Intent intent)
{
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon, "bla", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, Personal.class), 0);
    notification.setLatestEventInfo(context, "bla", "blabla", contentIntent);
    notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notification.sound = (Uri) intent.getParcelableExtra("notificationTone");
    if (intent.getBooleanExtra("vibrationEnabled", true)){
        notification.vibrate = (long[]) intent.getExtras().get("vibrationPatern");
    }

    manager.notify(NOTIFICATION_ID, notification);

}
}