简体   繁体   English

Android-Kotlin-安装APK文件不起作用

[英]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.我正在尝试将本地APK文件安装到我的应用程序中的设备上,但是无法正常工作。 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:我已经阅读了关于stackoverflow等的其他问题/帖子,并进行了以下操作,但仍无法弄清为什么它不起作用:

  • I downloaded and pushed the APK file (spotify) onto the device via $ adb push spotify.apk /sdcard/APKs/spotify.apk我通过$ adb push spotify.apk /sdcard/APKs/spotify.apk下载了APK文件(spotify)并将其$ adb push spotify.apk /sdcard/APKs/spotify.apk
  • I have rooted the device (Pixel C, running Android 8.1)我已经扎根了设备(运行Android 8.1的Pixel C)
  • I have the following WRITE_EXTERNAL_STORAGE , READ_EXTERNAL_STORAGE and INSTALL_PACKAGES declared in my AndroidManifest.xml我在AndroidManifest.xml声明了以下WRITE_EXTERNAL_STORAGEREAD_EXTERNAL_STORAGEINSTALL_PACKAGES

I am using the following Kotlin code:我正在使用以下Kotlin代码:

    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.我正在尝试将本地APK文件安装到我的应用程序中的设备上,但是无法正常工作。 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:我已经阅读了关于stackoverflow等的其他问题/帖子,并进行了以下操作,但仍无法弄清为什么它不起作用:

  • I downloaded and pushed the APK file (spotify) onto the device via $ adb push spotify.apk /sdcard/APKs/spotify.apk我通过$ adb push spotify.apk /sdcard/APKs/spotify.apk下载了APK文件(spotify)并将其$ adb push spotify.apk /sdcard/APKs/spotify.apk
  • I have rooted the device (Pixel C, running Android 8.1)我已经扎根了设备(运行Android 8.1的Pixel C)
  • I have the following WRITE_EXTERNAL_STORAGE , READ_EXTERNAL_STORAGE and INSTALL_PACKAGES declared in my AndroidManifest.xml我在AndroidManifest.xml声明了以下WRITE_EXTERNAL_STORAGEREAD_EXTERNAL_STORAGEINSTALL_PACKAGES

I am using the following Kotlin code:我正在使用以下Kotlin代码:

    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?但是什么也没发生,没有日志显示任何错误,也没有安装任何应用程序-有人知道这里发生了什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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