Android:如何取消隐藏应用

时间:2016-11-11 09:42:32

标签: android icons hide programmatically

我想允许我的Android应用的用户在他们想要的时候隐藏/取消隐藏它。 我已经有了执行隐藏/取消隐藏操作的代码,隐藏工作正常。 但是现在如何调用取消隐藏方法让应用程序恢复? 我的意思是,如果应用程序被隐藏,用户可以说,“点击一个按钮”,调用该方法使应用程序取消隐藏?

这是我的隐藏/取消隐藏代码:

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

1 个答案:

答案 0 :(得分:0)

这是我从其他应用中学到的一种方式。不是&#34;隐藏&#34;相反,图标会更改应用的图标和标签。将应用程序伪装成一些内置应用程序,例如&#34;设置&#34;或&#34;计算器&#34;。

另一种解决方案(可能更接近您的需求)是在您的应用中添加一个intent-filter,检测电话等内容。如果用户拨打某个号码,则取消隐藏您的应用。

请参阅this了解详情。

希望这会有所帮助。