Question

I'm working on my app. there's two app, one should be hide. and open by another one. I try code like this in app A

        PackageManager p = getPackageManager();
    p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

and try to open app A by code

Intent intent = MainActivity.this.getPackageManager()
                        .getLaunchIntentForPackage("com.example.hideicon");
                startActivity(intent); 

but it didn't work.

Was it helpful?

Solution 4

I solve my question . firstly you must hide your app icon by remove

 <category android:name="android.intent.category.LAUNCHER"

second you can add code in app B

 Intent intent = new Intent("com.example.hideicon");
              intent.setComponent(ComponentName
                  .unflattenFromString("com.example.hideicon/com.example.hideicon.MainActivity"));
              intent.addCategory("android.intent.category.LAUNCHER");
              startActivity(intent);

OTHER TIPS

For hide app icon

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(Test.this,com.example.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

For display app icon

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

It will not work since you have disabled the component and haven't enabled it before starting. To disable/enable it requires the permission.

please check this link i hope its useful to you.

reference link

remove launcher in manifest file from main acitivity.and programatically set it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top