Android Tutorial ? B4A Uninstalling a kiosk app

Hello all,
I've noticed 2 or 3 posts about not being able to uninstall a kiosk app because android:testOnly is missing from the manifest file, it's not in Erel's example.

If you just add the testOnly line to the manifest as you are supposed to for test packages then try to run/install that package on a device, you will see the following error message appears.

The above message appears because you are not installing the package as a test package using adb but just as a normal package without the -t option. below is a quick tutorial on how to install the package as a test package, and more importantly how to uninstall the app afterwards.

Take note:
Once you have added the android:testOnly to your manifest, you can only install that app via the adb install -t command. Whilst developing your app you will need to comment out the android:testOnly line or you will keep seeing the failed to install error above. Develop your app as usual and only install as a kiosk app as a test package if you need to uninstall the app afterwards. You might want to uninstall a kiosk app if for example you are developing the app on your person phone or tablet and not on the end device that will not need it uninstalling.

Download Erel's kiosk app example linked below.

Make 2 changes to Erel's kiosk app and follow my instructions very carefully.

1. At this point in time, DO NOT connect B4A to your Android device, NOT via B4A-Bridge, USB debugging or wirelessly.
2. Change the package name to whatever you want to, lets say to com.test.yourapp
3. Add the following line to the manifest file.
SetApplicationAttribute(android:testOnly,"true")

3. Run the app but NO NOT install the app on your device, you are running B4A JUST to assemble and create the APK file.
4. Connect your Android device via a USB cable to your B4A development machine.
5. Go to the projects folder then go into the Objects folder and copy the file called Kiosk.apk.
6 Find your Android_SDK\platform-tools folder and paste the Kiosk.apk file into the platform-tools folder. We will delete the file afterwards.
7. Open a command window in your Android_SDK\platform-tools folder location. I personally find the platform-tools folder in a window, once there I personally overwrite the path with cmd and press enter as that will open a command windows in the Android_SDK\platform-tools folder location.
8. Install the kiosk app by typing the following line in the command windows, press enter. The -t option is the important part here so DO NOT forget to include it.
adb install -t Kiosk.apk
The following should appear


8. Type the following line into the command window, press enter.
adb shell dpm set-device-owner com.test.yourapp/anywheresoftware.b4a.objects.AdminReceiver2

I'm using a clients actual app, so I've blurred out its package name.

That's it, your kiosk app is now installed on your device as a test package that you are now able to uninstall.

Lets uninstall your kiosk app which is installed as a test package.
Before you can uninstall the app, you fist have to remove the active admin linked to the test package. You remove the active admin by using the following line whilst the Android device is connected via the USB cable.
adb shell dpm remove-active-admin com.test.yourapp/anywheresoftware.b4a.objects.AdminReceiver2

You can now uninstall the kiosk app from your Android device as usual with no error or warning messages saying that you can't remove a protected package.

DO NOT FORGET TO DELETE THE Kiosk.apk FILE FROM THE Android_SDK\platform-tools folder.

Please note:

You do not have to use a USB cable but it is the easiest and faster to connect to your Android device via a cable. In fact you can use the command 'adb connect' followed by your Android device ip address to connect wirelessly to your Android device as long as your Android device is connected to the same WiFi as your B4A development machine. So for example 'adb connect 192.068.0.123' or 'adb connect 192.068.1.123'.


Enjoy...
 
Last edited:

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi... I installed the example by @Erel and I cannot uninstall it....
I tried recompiling with SetApplicationAttribute(android:testOnly,"true"), I installed successfully using adb but still I cannot uninstall the app.. I launched this command adb shell dumpsys device_policy but I got the following:
Enabled Device Admins (User 0, provisioningState: 3):
b4a.kiosk/anywheresoftware.b4a.objects.AdminReceiver2:
uid=10138
testOnlyAdmin=false
policies:
reset-password
limit-password
force-lock

Seems to ignore the testOnly flag... and infact I cannot uninstall neither from command line

my manifest
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

'uncomment to set as home activity
'AddActivityText(Main,
'<intent-filter>
'   <action android:name="android.intent.action.MAIN" />
'   <category android:name="android.intent.category.HOME" />
'   <category android:name="android.intent.category.DEFAULT" />
'</intent-filter>
')

AddApplicationText(<receiver android:name="anywheresoftware.b4a.objects.AdminReceiver2"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
    <meta-data android:name="android.app.device_admin"
            android:resource="@xml/device_admin" />
    <intent-filter>
        <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
    </intent-filter>
</receiver>)
SetApplicationAttribute(android:testOnly,"true")
CreateResource(xml, device_admin.xml,
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-policies>
        <limit-password />
        <reset-password />
        <force-lock />
    </uses-policies>
</device-admin>
)

what can I do now…?
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hi... I installed the example by @Erel and I cannot uninstall it....
Hello Mike,
Sadly I don't think that you'll be able to now, I never did. I personally now only create Kiosk apps with the android:testOnly,"true" line in the manifest from the very beginning of the project, thus I can then use

adb shell dpm remove-active-admin blah blah blah followed by adb uninstall <package_name>.

If you had first added the android:testOnly into the manifest then uninstalling the kiosk app is as simple as using just two adb commands or one adb command followed by the usual going to the apps tray and uninstalling the kiosk app.

The only way I've ever managed to remove a kiosk app without fist adding the android:testOnly into the registry, is by factory resetting the actual device in question.
 
Last edited:

Mike1970

Well-Known Member
Licensed User
Longtime User
Oh my god.. this is insane .. why this is not mentioned in the tutorial ?
 

Peter Simpson

Expert
Licensed User
Longtime User
Oh my god.. this is insane .. why this is not mentioned in the tutorial ?
I think it's because you're supposed to (for the most part) develop your kiosk app without the extra manifest code. Once you are happy with the kiosk app, you're expected to then add the manifest code and install the finished app onto the kiosk device. Me personally, I don't do that. I add the manifest code first with the testonly line. When developing the app I use a build condition to only run the standard manifest code ignoring the extra code in the manifest. Once I'm happy with the app I'll switch the build condition to run the entire manifest including the kiosk code which always incluslde the testOnly line and I install the APK file using -t, this can be done in a command windows or using CustomBuildActions in B4A.

I wrote the tutorial above that add two extra steps to Erels original example simply because I got fed up with factory resetting test devices after installing kiosk apps because I couldn't uninstall them. Basically adding testonly allows for removal of the active admin, thus you can then uninstall the kiosk app.
 

Mike1970

Well-Known Member
Licensed User
Longtime User
Me personally, I don't do that.
So, if I understood correctly when you develop the application you do it normally, like it's not a Kiosk app.

When you are satisfied of the result then you add in the manifest all the things needed to actually compile it as a Kiosk app (with the testOnly) and you install on every device using the adb command with the -t option. Correct?

I didn't know about this, I will do some researches here on the forum, at the moment as far as I understood I can do it manually, am I right?
 

Peter Simpson

Expert
Licensed User
Longtime User
Good morning Mike,
100% correctamundo (I must think that I'm the Fonz lol), that's exactly what I do. If I need to uninstall the app I can just run the following adb command to remove the active admin followed by a second adb uninstall command to remove the app itself from the device.

Remove admin:
adb shell dpm remove-active-admin com.test.yourapp/anywheresoftware.b4a.objects.AdminReceiver2
 

Mike1970

Well-Known Member
Licensed User
Longtime User
Ok now I'm able to uninstall kiosk apps if I need. thank you very much Peter D:

Now I can continue with my project ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…