Android自启动应用添加和限制

本篇介绍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); }

 

posted @ 2018-05-08 11:20  北京中普达研发  阅读(817)  评论(0编辑  收藏  举报