Search code examples
androidandroid-studioandroid-install-apk

Programmatically install/uninstall apk from local asset directory to real device in android studio


For Automation Testing I need to install on Apk programmatically and verify that the app is installed. and programmatically uninstall it and verify the app is uninstalled from the real device. I am not looking for a UI to download and install, without any UI when I run the java file in the android studio it should install/uninstall. Can anyone tell me how can I achieve this?


Solution

  • You can likely achieve this by using a combination of PackageInstaller and PackageManager

    As mentioned in the documentation for PackageInstaller, you'll need to be either the device owner or the affiliated profile owner, or it will require user intervention to complete installation.