android 设置系统闹钟和系统日历提醒 第一步:权限问题:
// 开启定时 findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra(AlarmClock.EXTRA_HOUR, mHour);
intent.putExtra(AlarmClock.EXTRA_MINUTES, mMinute);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, "hello world");
intent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
});
// 取消定时
findViewById(R.id.button3).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
intent.putExtra(AlarmClock.EXTRA_HOUR, mHour);
intent.putExtra(AlarmClock.EXTRA_MINUTES, mMinute);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, "hello world");
intent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
});
|