Android 桌面应用管理

我们开发的桌面应用管理功能:开机自己启动,home退不出去,关闭返回键,屏蔽状态栏,主要服务于学校使用的桌面管理应用

直接上代码

        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
主要添加这俩个属性    <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />

退出桌面应用功能
ArrayList<IntentFilter> intentList = new ArrayList<>();
ArrayList<ComponentName> cnList = new ArrayList<>();
context.getPackageManager().getPreferredActivities(intentList, cnList, null);
for(int i = 0; i < cnList.size(); i++) {
    IntentFilter dhIF = intentList.get(i);
    if(dhIF.hasAction(Intent.ACTION_MAIN) && dhIF.hasCategory(Intent.CATEGORY_HOME)) {//遍历过滤所有launcher
        try {
            String name = cnList.get(i).getPackageName();
            //清除原有的默认launcher
            context.getPackageManager().clearPackagePreferredActivities(name);
        }catch (Exception ex){
        }
    }
}
主要逻辑:获取系统中所有有桌面权限的应用APP集合,清空,系统会默认系统桌面。


代码就这些,最中要的一步就是手动设置他的权限,设置-应用管理-默认应用管理(一般在应用管理页面内的右上角是个图标,不同的系统不一样就在这个页面)-桌面-找到我们的app 确定
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值