让android定时关机的实现方法

先通过设置pendingIntent ..然后把设置到alarm 。。。来电具体的代码吧!

Java代码 收藏代码

Calendar calendar = Calendar.getInstance();
long nowTime = calendar.getTimeInMillis();//这是当前的时间
int hour = 你要设置的时间
int minutes = 你要设置的时间

Calendar myCal = Calendar.getInstance();
myCal.set(Calendar.HOUR_OF_DAY,hour);
myCal.set(Calendar.MINUTE,minutes);
long shutDownTime = myCal.getTimeInMillis();

Intent intent= new Intent();
intent.addAction();
PendingIntent pendingIntent = PendingIntent.getService(context,0,intent,0);
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

alarm.set(AlarmManager.RTC,shutDownTime -nowTime, pendingIntent);

下面是 service 。。。

接收到 Intent中的action 的话。。就启动。。

onStart(){
Intent intent = new Intent();
intent.setAction("android.intent.action.ACTION_SHUTDOWN");
sendBroadCast(intent);
}

更多相关文章

  1. 跟着第二行代码回顾Android--持久化技术
  2. Android常用三栏式滑动/滚动视图(View)的设计与实现代码
  3. Android Http请求的代码
  4. Android 源代码编后的目录分析
  5. 代码混淆
  6. PendingIntent实现原理和代码
  7. Eclipse For Android 代码自动提示功能
  8. android 查看解压后的.xml文件代码(axmlprinter2)
  9. 【Android】使用dex2jar 与JD-Gui 反编译APK文件,查看源代码

随机推荐

  1. AIR Native Extension的使用(Android)一
  2. Android中GPS定位的简单应用
  3. android源码下载方式
  4. Android(安卓)组件资源库
  5. Android(安卓)Porting Environment Set
  6. Android调用.NET Webservice报org.ksoap2
  7. Android(安卓)Studio bug - attribute 'a
  8. Android(安卓)Studio & ADT 快捷键配置文
  9. Ionic 运行报错No resource identifier f
  10. 从 Android(安卓)Sample ApiDemos 中学习