How to hide/unhide an application from Launcher when the application uses a permission?
Asked Answered
J

1

7

I have developed an Android application that allows the user to change some system settings. Once the user has configured the application, there is no reason to launch it anymore. That's why many users have asked me to add an option to hide the application from the launcher.

I tested the solution of 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:

enter image description here

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?

Jelena answered 20/9, 2019 at 9:26 Comment(2)
I'm not sure but you may need to get permission from user programatically.Batrachian
Thank you for your answer. The android.permission.SET_WALLPAPER permission does not have to be granted by the user. It is also possible to see on the gif that the permissions setting is grayed out in the Settings app.Jelena
S
4

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.
Swordcraft answered 23/9, 2019 at 18:33 Comment(3)
It's not the answer I was hoping for, but it's the right one. Thank you!Jelena
Did you find a solution?Rm
@HamzaEzzaydia I think there won't be a solution because Android has stopped support for the said functionalitySwordcraft

© 2022 - 2024 — McMap. All rights reserved.