如何访问下载文件夹?

用户名

我正在尝试apk从设备的下载目录安装我的硬编码解决方案就像一个魅力一样-

   Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "update.apk")), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

但是一旦我将其更改为

       Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "update.apk")), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

我解析包错误。我究竟做错了什么????

萨加尔

传回的值

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

/ storage / emulated / 0 / Download,其末尾缺少“ /”。您的路径应为“ /update.apk”

您需要按以下方式使用它:

intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/update.apk")), "application/vnd.android.package-archive");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章