使用电源按钮解除警报?

时间:2015-05-19 13:16:01

标签: android

从答案到我在这里找到的其他问题,似乎无法从服务中听取电源按钮等硬件按钮,但是,我需要在按下电源按钮时解除警报。在Android中是否有可能实现这一目标?这是我的警报服务代码:

public class AlarmService extends IntentService {
private NotificationManager alarmNotificationManager;

public AlarmService() {
super("AlarmService");
}

@Override
public void onHandleIntent(Intent intent) {
sendNotification("Wake Up! Wake Up!");
}

private void sendNotification(String msg) {
Log.d("AlarmService", "Preparing to send notification...: " + msg);
alarmNotificationManager = (NotificationManager) this
        .getSystemService(Context.NOTIFICATION_SERVICE);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
        new Intent(this, Time_Date.class), 0);

NotificationCompat.Builder alamNotificationBuilder = new 
NotificationCompat.Builder(

this).setContentTitle("Alarm").setSmallIcon(R.drawable.ic_launcher)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
        .setContentText(msg);


alamNotificationBuilder.setContentIntent(contentIntent);
alarmNotificationManager.notify(1, alamNotificationBuilder.build());
Log.d("AlarmService", "Notification sent.");
}
}

0 个答案:

没有答案