1.首先写了一个按钮
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.chenjun.jun_0723.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置闹钟"
android:onClick="setAlarmOnce"
></Button>
</LinearLayout>
2.然后写Java代码设置闹钟
package com.chenjun.jun_0723;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;