Android程序:系统重启+开机自动运行+屏幕解锁
来源:互联网 发布:mac 将wma转换成mp3 编辑:程序博客网 时间:2024/05/21 22:32
Android程序:系统重启+开机自动运行+屏幕解锁
android程序自动重启,释放内存。
1、系统自动重启方法
private void shutdownDevice(Context context){ String cmd = "su -c reboot"; try { Runtime.getRuntime().exec(cmd); } catch (IOException e) { // TODO Auto-generated catch block
new AlertDialog.Builder(context).setTitle("Error").setMessage( e.getMessage()).setPositiveButton("OK", null).show(); } }
2、系统重启后程序自动运行
先在AndroidManifest文件中添加权限和注册广播
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".BootBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
添加BootBroadcastReceiver.class
static final String ACTION = "android.intent.action.BOOT_COMPLETED"; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION)){ Intent sayHelloIntent=new Intent(context,activity.class); sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(sayHelloIntent); } }
3、程序启动时屏幕解锁
先在AndroidManifest文件中添加权限
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
onCreate中加入,最好在setContentView(R.layout.main)之前
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD, WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.main);
0 0
- Android程序:系统重启+开机自动运行+屏幕解锁
- Android开机自动运行程序
- Android开机自动运行程序
- Android开机自动运行程序
- android 开机自动运行程序
- Android 开机自动运行程序
- 开机自动运行程序【Android】
- Android开机自动运行程序
- android 开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- android应用开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- android应用开机自动运行程序
- android应用开机自动运行程序
- Android实现开机自动运行程序
- macro in gtk
- UIBarItem UITabBarItem常用方法
- sublime写插件,插入时间
- ios 调用短信接口发送指定内容的消息
- 一步步学习SPD2010--第一章节--探索SPD2010(4)附--使用SharePoint Designer创建站点(命名URL最佳实践)
- Android程序:系统重启+开机自动运行+屏幕解锁
- 猜数字游戏
- Tomcat源码分析------ 一次完整请求的里里外外
- 解决163/sohu/sina不能够收到PHP MAIL函数发出邮件的问题
- 服装门店神秘顾客调查方案-调查目的及内容
- nyoj-145-聪明的小珂
- ioctl函数简介
- IOS iphone中结束电话后返回自己的应用
- 中水处理设备分类方法及工艺流程选择