给系统闹钟设置时间, 为什么不自己写一个, 还不是因为自己技术太菜, 不能保证自己写的闹钟会被在 杀进程 关机的情况下被唤起, so no bb show code:
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM); intent.putExtra(AlarmClock.EXTRA_ALARM_SEARCH_MODE, AlarmClock.ALARM_SEARCH_MODE_LABEL); intent.putExtra(AlarmClock.EXTRA_MESSAGE, "闹钟来了"); //闹钟标题 intent.putExtra(AlarmClock.EXTRA_HOUR, Integer.parseInt(hour)); //闹钟时间 一定要是int类型 intent.putExtra(AlarmClock.EXTRA_MINUTES, Integer.parseInt(minutes)); intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true); //默认铃声 intent.putExtra(AlarmClock.EXTRA_VIBRATE, true); //震动 startActivity(intent);
特别注意:
1. 时间一定得是int类型, 否则设置失败.
2. 添加权限: <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
是不是很简单!