Install an APK after downloading to ASD - works on all Android versions

With this extension you can download an APK to the ASD (app-specific directory) and install it. This doesn’t require WRITE / READ_EXTERNAL_STORAGE permissions.

However, you can also install an APK from another directory (e.g. the /Download folder) (with READ permissions).

This should work on all Android versions, especially with Android 9, 10, 11.

Version 1 (Oct 25, 2020) → AI2 version (→ use only with AI2):
de.bodymindpower.InstallAPK.aix (9.1 KB)

Blocks - version 1

grafik

Note: The → InstallAPK.Install_pathAPK ← block works only with the compiled app (APK).

Version 2 (Oct 28, 2020)
de.bodymindpower.InstallAPK.aix (9.6 KB)

Blocks - version 2

You can now create the /Download dir in the ASD:

/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/Download/

and also subfolders in this dir, e.g.:

/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/Download/myAPKs/

Version 3 (Nov 1, 2020)
de.bodymindpower.InstallAPK.aix (12.9 KB)
DownloadCompleted event added.

Example / blocks → download APK from Google Drive

Update v6 (May 3, 2022):
de.bodymindpower.installApk.aix (11.2 KB)
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
added to Manifest.

With version 5 there seems to be a compiling issue with some special extensions. This has been fixed in version 6. In addition, two new blocks have been added to check if the APK has already been downloaded (exists) and to delete the APK again after downloading. (This version was now compiled with Rush.)

12 Likes

thumbsup2
Well done Anke!

2 Likes

thank you for your contribution! looks great!

do you also accept feature requests? :wink: we also could use

  • a method to list all files of the ASD including subdirectories and
  • a method to create a subdirectory inside the ASD...

only the Install method or all methods? To be able to test in the companion app it would be great, if as much methods as possible also work while using the companion app...

keep up the good work!

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

1 Like

No, only the Install method.

I'll try, but ...
(as you know I'm still a beginner with extensions).
Probably I need some help from an extension expert like you ... :man_shrugging:

2 Likes

Thanks, maybe you want to add a link to this extension (→ AI2 version) on your website:

because this link is only for the → Kodular version:


Extension to Install APK from app-specific directory (ASD) by BodyMindPower

1 Like

EDIT: I forgot to mention that for devices with API < 19 (KitKat) WRITE_EXTERNAL_STORAGE permission is required, but this permission is granted at install-time for devices with API < 23 (because it is declared in the Manifest).

"On Android 4.4 (API level 19) or higher, your app doesn't need to request any storage-related permissions to access app-specific directories within external storage."
https://developer.android.com/training/data-storage/app-specific

Thank you for the great work!
:+1:

1 Like

I made an update and added some methods for creating subdirectories in the ASD as suggested by @Taifun:

Version 2 (Oct 28, 2020)
de.bodymindpower.InstallAPK.aix (9.6 KB)

You can now create the /Download dir in the ASD:

/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/Download/

and also subfolders in this dir, e.g.:

grafik

/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/Download/myAPKs/

2 Likes

(added to FAQ)

sorry for my beginner question, what's the advantage of installing an APK to ASD ?

See in the description above:

I put my question wrong, why to make an app for installing another app ?

There can be a variety of reasons.
Maybe you want to ask a user who was looking for it:

As Anke wrote there can be many reasons.
For example, in my current project i don't use playstore because of lead time and it is a private app, so i use the extension for self install the newest version from our own server. Of course it can be download and install manually, but not every user is software- and phone-guru so i make it easier for them.

I only wish it would be possible to avoid click on isntall too.

done
thank you
Taifun

1 Like

image
image

Dear Anke,
An error occurred such as image1
Apk (MIT AI) is run on an android version such as image2

Show your blocks.
And try this test APK:

  • Does it work on your device?
  • Which device and Android version do you have?

I've found the reason why the installAPK method doesn't work on devices with Android > 7. This line is missing in the Manifest of the Companion APK:

android:name="com.google.appinventor.components.runtime.multidex.MultiDexApplication"

If I add this line in the Manifest, it works fine also on Android 8, 9, 10, 11.
Maybe you or @ewpatton can tell more about this.

1 Like

This shouldn't be needed on Android 5 and higher. Prior to Android 5, MultiDex was needed for larger apps that ended up with their classes.dex file split across multiple files. Starting with Android 5, Android converts the dex files to oat files to work with the new Android Runtime (ART) on install so multidex is no longer needed. If you increase the minSDK of the app to 21 you shouldn't need the multidex declaration.

When I create an APK with my extension, this line is created in the Mainifest:

<application android: debuggable = "false" android: icon = "@ mipmap / ic_launcher" android: label = "installAPK AI2" android: name = "com.google.appinventor.components.runtime.multidex.MultiDexApplication"

and everything works as it should (on all Android versions) ...