美文网首页
android 10.0网络问题 install app jav

android 10.0网络问题 install app jav

作者: hao_developer | 来源:发表于2020-09-21 11:06 被阅读0次

这个原因很简单,这个错误是检查AndroidManifest.xml,里面的
1:在AndroidManifest.xml配置以下配置

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="包名.fileProvider"
    android:exported="false"
    android:grantUriPermissions="true"
   >
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
image.png
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <paths>
        <external-files-path name="images" path="Pictures" />
        <files-path path="files" name="files" />
        <cache-path path="files" name="cache" />
        <external-path path="files" name="external" />
        <external-files-path path="files" name="externalfiles"/>
        <!-- 此标签需要 support 25.0.0以上才可以使用-->
        <external-cache-path  path="files" name="externalcache"/>
        <external-path name="camera_photos" path="."  />

        <external-cache-path  path="my_images" name="Android/data/com.gs.common/files/Pictures/"/>
        <external-cache-path  path="images" name="Pictures/"/>
        <external-cache-path  path="dcim" name="DCIM/"/>

        <files-path name="images" path="Android/data/com.example.package.name/files/Pictures/OriPicture/" />
        <external-path name="images" path="Android/data/com.example.package.name/files/Pictures/OriPicture/" />
        <external-files-path name="images" path="files/Pictures/OriPicture" />
        <root-path name="images" path="" />

    </paths>

</resources>

尤其注意android:authorities="包名.fileprovider",注意大小写
app安装

 //安装apk
    fun installApk(context: Context, file: File) {
        if (context == null) return
        val authority: String =
            getApplicationContext().packageName.toString() + ".fileProvider"
        val apkUri: Uri = FileProvider.getUriForFile(context, authority, file)
        val intent = Intent(Intent.ACTION_VIEW)
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        //判读版本是否在7.0以上
        if (Build.VERSION.SDK_INT >= 24) {
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
        } else {
            intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive")
        }
        context.startActivity(intent)
        //弹出安装窗口把原程序关闭。避免安装完毕点击打开时没反应
        android.os.Process.killProcess(android.os.Process.myPid())
    }

\color{red}{一定要注意androidmanifest.xml文件里面配置和你调用安装配置的:包名+".fileProvider"这段一定一定一定保持一直,要不然,你就自己坑自己吧}\
\color{red}{**包名+".fileProvider" 一定要注意大小写**}\

相关文章

网友评论

      本文标题:android 10.0网络问题 install app jav

      本文链接:https://www.haomeiwen.com/subject/yuqvyktx.html