Android自启动应用添加和限制
16lz
2021-01-25
本篇介绍Android开机自动启动应用的开发过程。
1:添加自启动权限
在AndroidManifest.xml添加权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2:添加自启动接收,决定用哪个BroadcastReceiver作为应用入口
在AndroidManifest.xml添加入口
<receiver android:name="com.zpd.scanadapter.BootUp" ><intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" />intent-filter>receiver>
BootUp的实现
public class BootUp extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //在此启动应用 }}
3:应用退出限制
A:监听BACK返回键
@Override public boolean onKeyDown(int keycode, KeyEvent e) { if (keycode == KEYCODE_BACK) { return true; } return super.onKeyDown(keycode, e); } @Override public boolean onKeyUp(int keycode ,KeyEvent e) { if (keycode == KeyEvent.KEYCODE_BACK) { return true; } return super.onKeyUp(keycode,e); }
B:禁止HOME键
此项功能需要调用到我司CapipadSDK.jar包里的CapipadInterfaceManager的setHomekeyandStatusbarState()方法。
详细可参看我司的接口说明书:http://www.cnblogs.com/ouyanghy/p/8479128.html
调用如下:
{
boolean state;//true key home enable,false disable
CapipadInterfaceManager intf= new CapipadInterfaceManager(getContext());
intf.setHomekeyandStatusbarState(state);}
转载于:https://www.cnblogs.com/ouyanghy/p/9007221.html
更多相关文章
- Android(安卓)ContentProvider简介
- [Android(安卓)Pro] service中显示一个dialog 或者通过windowman
- Android(安卓)10动态申请读写权限
- Android(安卓)SD卡中压缩包解压(ZIP文件)
- android短信开发
- Android(安卓)向桌面添加删除快捷方式
- Android开发之实现锁屏功能
- 【android】 Unable to open content: file:///sdcard/hello.3gp
- android开机自动唤醒屏幕、打开锁屏页并启动app