简体   繁体   中英

Android - Kotlin - Install APK file not working

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:

  • I downloaded and pushed the APK file (spotify) onto the device via $ adb push spotify.apk /sdcard/APKs/spotify.apk
  • I have rooted the device (Pixel C, running Android 8.1)
  • I have the following 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:

  • I downloaded and pushed the APK file (spotify) onto the device via $ adb push spotify.apk /sdcard/APKs/spotify.apk
  • I have rooted the device (Pixel C, running Android 8.1)
  • I have the following 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM