android基础-开机自启动
来源:互联网 发布:淘宝整点秒杀怎么进 编辑:程序博客网 时间:2024/06/10 23:33
开机自启动,当时在开发Qt的时候主要是通过写注册表来实现的,也就是把你的软件名称的路径写入注册表中,然后当电脑启动的时候,就会启动你的软件!呵呵。。。PC端是这样,那手机端是怎么样呢?今天看到博客说是当手机启动的时候会发出一个广播ACTION_BOOT_COMPELETE,因此我们需要做就是接受这个广播,然后再执行我们的操作,就是启动第一个activity然后就可以啦!
ok,废话不多说,直接上代码。
1,首先我们要定义一个类来接收广播
Public class autostartReceiver extends BoradcastReceiver{ @Override Public void onReceive(Context context,Intent intent){if(Intent.getAction().equals("android.intent.action.BOOT_COMPELETED")){Intent intent1=new Intent();intent1.setClass(context,MainActivity.calss);intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(intent); } }}
2,然后在AndroidManifest.xml中定义改类,并添加开机权限
<receiver android:name=".autostartReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPELETED"/> <category android:name="android.intent.category.LAUNCHER"/> </Intent-filter></receiver>
启动开机权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPELETED"/>
ok,上面就是关于android开机自启动的,下面我也给大家讲述一下Qt开机自启动的方法吧!
Qt中主要是用到QSetting这个类来进行开机自启动的处理,要详细查看的话就去看帮助文档,再详细不过,这里不讲述。
这里写一个函数来,参数是bool型的,true就自启动,false不自启动
直接上代码:
#define path "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" //这是注册表的地址void autoStart(bool isStart){QString app_name = QApplication::applicationName();QSettings setting = new QSettting(path,Qsettings::NativeFormat);if(isStart){QString app_path = QApplication::applicationPath();setting->setValue(app_name,app_path.replace("/","\\"));}else{setting->remove(app_name);}}
0 0
- android基础-开机自启动
- Android开机自启动
- Android开机自启动。
- 【Android】开机自启动
- 【Android】开机自启动 .
- Android开机自启动
- 【Android】开机自启动
- android开机自启动
- 【Android】开机自启动
- Android 开机自启动
- android 开机自启动
- android 开机自启动
- Android开机自启动
- 【Android】开机自启动
- Android开机自启动
- android开机自启动
- android开机自启动
- Android 开机自启动
- 线性表练习题3
- android屏幕翻转
- 个人站长是一个非常特别的群体,通常就是一个人对着一台电脑
- DCMP2.0项目总结_页面
- 解决ADT中adb server didnt ack问题
- android基础-开机自启动
- 稀奇古怪备忘录
- 数据库分类及介绍
- 小知识——Matlab常见用法
- java 格式化长度为播放器显示格式
- ios5 代码获取storyboard文件的对象
- PHP数据库的连接与代码实现
- 递归和动态规划的转换
- flushMode