0

I've been trying to get an app icon to be hidden using c# in unity. I tried implementing the android code below:

    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);

So, my code is:

AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaClass cn = new AndroidJavaClass ("android.content.ComponentName");

launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage",bundleId);
packageManager.Call<AndroidJavaObject>("setComponentEnabledSetting",cn,packageManager.Get<int>("COMPONENT_ENABLED_STATE_DISABLED"),packageManager.Get<int>("DONT_KILL_APP"));
ca.Call ("startActivity", launchIntent);

cn.Dispose ();
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();

When I build and run for android, the line indicating packagemanager is not getting called. What am I missing here? Please help!

Shreenath M
  • 143
  • 1
  • 2
  • 8

2 Answers2

0

If you have your manifest files for the apk,then by removing the launcher category in manifest you can hide your app.Only apps declared as launcher will be visible in the screen. May I know why you want to hide them programatically?

0

If you have your manifest files for the apk,then by removing the launcher category in manifest you can hide your app.Only apps declared as launcher will be visible in the screen.You will need to use a broadcast receiver to launch an app without the launcher category. May I know why you want to hide them programatically.?Why don't you create a Java object for the package manager,just like how you have done for current activity.