Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 744
Charles Annic Avatar asked Sep 20 '19 09:09

Charles Annic


1 Answers

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.
like image 188
Farid Avatar answered Nov 14 '22 00:11

Farid