android app设置文件共享

时间:2015-08-20 17:06:39

标签: java android xml file-sharing

我一直在使用Android开发人员教程来发送数据。这个问题是关于发送二进制内容。 我已经设置了我的MainActivity.java文件的sendMessage()方法:

public void sendMessage(View view) {       
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
        shareIntent.setType("image/jpeg");
        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
}

我已将AndroidManifest.xml文件设置为包含一个标记,该标记授予URI权限并定位资源@ xml / file_paths(... / xml / file_paths.xml)。我已经将... / file_paths.xml设置为:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <files-path name="send_images" path="images/"/>
    </paths>
</PreferenceScreen>

此.xml文件引用files / images /目录和send_images目录以附加到fileprovider权限。我还没有创建一个文件/图像目录,这是我困惑的根源。该教程说它们是内部存储区域的一部分。那是什么?我在哪里设置这些目录?是应该在运行时/运行期间创建还是在编译时加载到应用程序中?

1 个答案:

答案 0 :(得分:0)

  

我已经将... / file_paths.xml设置为:

我不知道为什么你有<PreferenceScreen>元素。如果您使用FileProvider,则XML资源的根元素必须是<paths>元素。

  

教程说它们是内部存储区域的一部分。那是什么?

Internal storage是您应用的板载闪存的私有区域。

  

我在哪里设置这些目录?

该XML中只引用了一个目录:images/。鉴于您使用的是<files-path>元素,images/引用getFilesDir()的子目录,如the documentation for FileProvider所述。

  

是应该在运行时/运行期间创建还是在编译时加载到应用程序中?

您只能在运行时将文件放入内部存储空间。