相关疑难解决方法(0)

我写了一个文件到Environment.DIRECTORY_DOWNLOADS,为什么我不能通过下载应用程序看到它?

我在Environment.DIRECTORY_DOWNLOADS目录中编写(写入,而不是下载,确切地说是我的应用程序的SQLite数据库的转储)文件.

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, "db.csv");
Run Code Online (Sandbox Code Playgroud)

如果我用文件浏览器浏览手机,我可以正确看到该文件

  /storage/emulated/0/Download
Run Code Online (Sandbox Code Playgroud)

目录,以及其他下载.

但是,如果我打开下载应用程序,它不会显示...

我还需要做什么才能让文件显示在下载应用程序中?

android

12
推荐指数
2
解决办法
1万
查看次数

Android中的FileUriExposedException

我需要在包含图像的内部存储中打开文件夹.

我使用以下代码.

Java的

 File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),  "MyPhotos");
Intent intent = new Intent(Intent.ACTION_VIEW);
String path =folder.getPath();
Uri myImagesdir = Uri.parse("file://" + path );
intent.setDataAndType(myImagesdir,"*/*");   
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

PATHS

 <paths xmlns:android="http://schemas.android.com/apk/res/android">
     <external-path name="images" path="Pictures" />
     <external-path name="external_files" path="."/>
     <external-path name="files_root" path="Android/data/${applicationId}"/> </paths>
Run Code Online (Sandbox Code Playgroud)

表现

  <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.android.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
Run Code Online (Sandbox Code Playgroud)

XML/file_paths

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="images" path="Pictures" />
    <external-path name="external_files" path="."/>
    <external-path name="files_root" path="Android/data/${applicationId}"/>
</paths>
Run Code Online (Sandbox Code Playgroud)

错误

致命异常:主要进程:android.apps.bnb.company.myphotos,PID:22482 android.os.FileUriExposedException:file:/// storage/emulated/0/Pictures/MyPhotos通过Intent.getData()暴露在app之外

是否有其他方法可以在内部存储中打开文件夹?谢谢!

更新#1

使用这个arcticle https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en我更换了

Uri myImagesdir = Uri.parse("file://" …
Run Code Online (Sandbox Code Playgroud)

java directory android android-intent

10
推荐指数
2
解决办法
9874
查看次数

标签 统计

android ×2

android-intent ×1

directory ×1

java ×1