开发闹钟应用程序,该应用程序可以设置闹钟,并在设定的时间内播放默认声音。但是,在默认的Android Alarmclock中,当闹钟响起时,会打开一个对话框来关闭闹钟,我的问题是我是否需要从我的应用中创建那种自定义Activity,以便能够解除闹钟,或者是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.");
}
}