AlarmManager aManager = (AlarmManager) mcontext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("MYALARMRECEIVER");
intent.putExtra("msg","提醒时间到了");
PendingIntent pi = PendingIntent.getBroadcast(mcontext,0,intent,0);
Date date=new Date(System.currentTimeMillis());
long time1=date.getTime();
Log.d("555555555558888",String.valueOf(time1));
aManager.setRepeating(AlarmManager.RTC_WAKEUP, time1,600*1000,pi);
public class MyReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent){
String msg = intent.getStringExtra("msg");
Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
Log.d("5555555","闹钟响了");
}
}
<?xml version="1.0" encoding="utf-8"?>
package="com.example.zou.ti">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CreatEvent">
</activity>
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="MYALARMRECEIVER" />
</intent-filter>
</receiver>
</application>