I am trying to install a local APK file onto the device within my app, however it is not working. I've read other questions/posts on stackoverflow etc. and have done the following, but still can't figure out why it wouldn't work:
$ adb push spotify.apk /sdcard/APKs/spotify.apk
WRITE_EXTERNAL_STORAGE
, READ_EXTERNAL_STORAGE
and INSTALL_PACKAGES
declared in my AndroidManifest.xml
I am using the following Kotlin code:
if (Build.VERSION.SDK_INT >= 24) {
try {
val m = StrictMode::class.java.getMethod("disableDeathOnFileUriExposure")
m.invoke(null)
} catch (e: Exception) { e.printStackTrace() }
}
val intent = Intent(Intent.ACTION_VIEW)
val file = File(Environment.getExternalStorageDirectory().toString() + "/APKs/" + "spotify.apk")
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
But nothing happens, no log appears indicating any error and no app is installed - does anybody know what's going on here?
I am trying to install a local APK file onto the device within my app, however it is not working. I've read other questions/posts on stackoverflow etc. and have done the following, but still can't figure out why it wouldn't work:
$ adb push spotify.apk /sdcard/APKs/spotify.apk
WRITE_EXTERNAL_STORAGE
, READ_EXTERNAL_STORAGE
and INSTALL_PACKAGES
declared in my AndroidManifest.xml
I am using the following Kotlin code:
if (Build.VERSION.SDK_INT >= 24) {
try {
val m = StrictMode::class.java.getMethod("disableDeathOnFileUriExposure")
m.invoke(null)
} catch (e: Exception) { e.printStackTrace() }
}
val intent = Intent(Intent.ACTION_VIEW)
val file = File(Environment.getExternalStorageDirectory().toString() + "/APKs/" + "spotify.apk")
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
But nothing happens, no log appears indicating any error and no app is installed - does anybody know what's going on here?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.