当应用程序使用权限时,如何从启动器中隐藏/取消隐藏应用程序? [英] How to hide/unhide an application from Launcher when the application uses a permission?

查看:174
本文介绍了当应用程序使用权限时,如何从启动器中隐藏/取消隐藏应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Android应用程序,允许用户更改某些系统设置.一旦用户配置了应用程序,就没有理由再启动它了.这就是为什么许多用户要求我添加一个选项以在启动器中隐藏该应用程序的原因.

我测试了

这是我的清单:

 <?xml version ="1.0" encoding ="utf-8"?>< manifest xmlns:android ="http://schemas.android.com/apk/res/android"package ="com.cannic.apps.hideapptest">< uses-permission android:name ="android.permission.SET_WALLPAPER"/><应用android:allowBackup ="true"android:icon ="@ mipmap/ic_launcher"android:label ="@ string/app_name"android:roundIcon ="@ mipmap/ic_launcher_round"android:supportsRtl ="true"android:theme ="@ style/AppTheme"><活动android:name =.MainActivity"android:label ="@ string/app_name"android:theme ="@ style/AppTheme.NoActionBar"><意图过滤器>< action android:name ="android.intent.action.MAIN"/>< category android:name ="android.intent.category.LAUNCHER"/></intent-filter></activity></应用程序></manifest> 

所以我的问题是:当应用程序请求权限时,是否可以从启动器中隐藏该应用程序?

解决方案

我不确定官方不支持"是否是答案.但不幸的是,根据this post.

I hide the application this way:

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

I unhide the application this way:

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

It works very well... as long as I don't add permission to my application.

For example, I use the following permission:

<uses-permission android:name="android.permission.SET_WALLPAPER" />

And when I add this permission to the Manifest, the application does not disappear from the launcher. And, when I click on it it starts the Settings application on my application page, as shown in the following gif:

Here is my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cannic.apps.hideapptest">

    <uses-permission android:name="android.permission.SET_WALLPAPER" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

So my question is the following: Is there a way to hide an application from the launcher when the application asks permissions?

解决方案

I'm not sure if "officially not supported" is an answer or not. But unfortunately, according to docs:

As of Android Q, at least one of the app's activities or synthesized activities appears in the returned list unless the app satisfies at least one of the following conditions:

  • The app is a system app.
  • The app doesn't request any permissions.
  • The tag in the app's manifest doesn't contain any child elements that represent app components.

Additionally, the system hides synthesized activities for some or all apps in the following enterprise-related cases:

  • If the device is a fully managed device, no synthesized activities for any app appear in the returned list.
  • If the current user has a work profile, no synthesized activities for the user's work apps appear in the returned list.

这篇关于当应用程序使用权限时,如何从启动器中隐藏/取消隐藏应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆