0

I want to allow the users of my Android app to hide/unhide it when they want. I already have the code to perform the hide/unhide actions, and the hiding works fine. But now how can I call the unhide method to let the app back? I mean, if the app is hidden, where can the user, let's say, "click a button" that calls the method to make the app unhide?

Here is my hide/unhide code:

// method to hide the app icon
 public static void hideAppIcon(final Context context)
    {
     PackageManager p = context.getPackageManager();
     // activity which is first time open in manifest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
     ComponentName componentName = new ComponentName(context, SplashActivity.class);
     p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }


 // method to unhide the app icon
 public static void unhideAppIcon(final Context context)
    {
     PackageManager p = context.getPackageManager();
     // activity which is first time open in manifest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
     ComponentName componentName = new ComponentName(context, SplashActivity.class);
     p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ciammarica
  • 141
  • 3
  • 17

1 Answers1

0

Here's a way I've learned from another app. Not "hiding" the icon, instead, change the icon and label of your app. Disguise the app as some built-in apps like "Settings" or "Calculator".

Another solution (which might be closer to your need) is to add an intent-filter in your app, detecting something like phone calls. If users call a certain number, you unhide your app.

see this for more infomation.

Hope this will help.

Community
  • 1
  • 1
Tomaz Wang
  • 316
  • 4
  • 11
  • You might get errors when you're calling MainAcitvity while the app is hidden. You have to unhide it. – Tomaz Wang Nov 11 '16 at 10:51
  • changing icon and label sounds like a nice alternative, could you please send me some references / code about that? That was my first option, but I read that only system apps can change icon programmatically, that's why I chose to hide the icon instead... Thanks! – Ciammarica Nov 11 '16 at 11:27
  • changing icon is impossible as you know. But there are some workarounds. Check out [this post](http://stackoverflow.com/q/1103027/4319678). Hope it will help. – Tomaz Wang Nov 15 '16 at 10:48