im struggling when using the method to force stop another running application in my app. I already see another thread in StackOverflow that my app need signed apk to run the force stop method. However, i already build and run in my android but it still says like below: Caused by: java.lang.SecurityException: Permission Denial: forceStopPackage() from pid=xxx, uid=xxx requires android.permission.FORCE_STOP_PACKAGES This is my code:
val am = applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val forceStopPackage: Method = am.javaClass.getDeclaredMethod("forceStopPackage", String::class.java)
forceStopPackage.isAccessible = true
forceStopPackage.invoke(am, radPackage) //radPackage is active running app
Here is the option to build signed app:
And here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xxx.xxx">
<permission android:name="android.permission.FORCE_STOP_PACKAGES"
android:protectionLevel="signature"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS" />
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"
tools:ignore="ProtectedPermissions" />
</manifest>
Ill try running the app in real device with version Android P (API 28).