I`m interested in knowing if it is possible to programmatically install a dynamically downloaded apk from a custom Android application.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Just an extension, if anyone need a library then this might help. Thanks to Raghav
It's worth noting that if you use the
DownloadManager
to kick off your download, be sure to save it to an external location e.g.setDestinationInExternalFilesDir(c, null, "<your name here>).apk";
. The intent with a package-archive type doesn't appear to like thecontent:
scheme used with downloads to an internal location, but does likefile:
. (Trying to wrap the internal path into a File object and then getting the path doesn't work either, even though it results in afile:
url, as the app won't parse the apk; looks like it must be external.)Example:
Try this - Write on Manifest:
Write the Code:
First add the following line to AndroidManifest.xml :
Then use the following code to install apk:
The solutions provided to this question are all applicable to
targetSdkVersion
s of 23 and below. For Android N, i.e. API level 24, and above, however, they do not work and crash with the following Exception:This is due to the fact that starting from Android 24, the
Uri
for addressing the downloaded file has changed. For instance, an installation file namedappName.apk
stored on the primary external filesystem of the app with package namecom.example.test
would be asfile:///storage/emulated/0/Android/data/com.example.test/files/appName.apk
for
API 23
and below, whereas something likefor
API 24
and above.More details on this can be found here and I am not going to go through it.
To answer the question for
targetSdkVersion
of24
and above, one has to follow these steps: Add the following to the AndroidManifest.xml:2. Add the following
paths.xml
file to thexml
folder onres
in src, main:The
pathName
is that shown in the exemplary content uri example above andpathValue
is the actual path on the system. It would be a good idea to put a "." (without quotes) for pathValue in the above if you do not want to add any extra subdirectory.Write the following code to install the apk with the name
appName.apk
on the primary external filesystem:No permission is also necessary when writing to your own app's private directory on the external filesystem.
I have written an AutoUpdate library here in which I have used the above.
Follow these steps:
1 - Add the following to the
AndroidManifest.xml
:2 - Add the following paths.xml file to the xml folder(if not exist create it) on res in src, main
The pathName is that shown in the exemplary content uri example above and pathValue is the actual path on the system. It would be a good idea to put a "." for pathValue in the above if you do not want to add any extra subdirectory.
3 - Write the following code to Run Your Apk files:
And Thanks To Ali Nemati Hayati to be the First To write Solution Profile ali-nemati-hayati