I am going to write a project that can hide another apps. I do research and find some useful code and it work well to hide my app. You can see my code below:
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
And the problem is that, I don't know how can I hide another apps. I have tried to do lot of research but I still cannot find any solution. So you can look at my code below (but it is not working to hide another apps, but to hide my own is working well):
PackageManager p = getPackageManager();
ComponentName com = new ComponentName("com.example.pro", "com.example.pro.classname");
p.setComponentEnabledSetting(com, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
I know that the first parameter for ComponentName is a package name of the app, and second parameter is a main activity name of the app that I want to hide. But it always force close every time i changed both of this parameters to another value. But if I change the first parameter to package name of my app and second parameter to the main activity name of my app, it work well like the first code I show above.
And I have some log that i got when my app force close below:
04-01 22:56:32.884 13339-13339/com.example.pro D/AndroidRuntime: Shutting down VM 04-01 22:56:32.884 13339-13339/com.example.pro E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.pro, PID: 13339
java.lang.SecurityException: Permission Denial: attempt to change component state from pid=13339, uid=10613, package uid=10464
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:4073)
at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:1839)
at com.example.pro.MainActivity$1.onClick(MainActivity.java:142)
at android.view.View.performClick(View.java:5191)
at android.view.View$PerformClick.run(View.java:20931)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
So the problem is that, how can I hide another apps ? Any other code/method/suggest/example is fine. And i'd appreciate your help. Thanks.