gpt4 book ai didi

java - 共享内部文件给出 : Failed to find configured root that contains/data/data/com. myapp/app_profiles/profile_1/games/game_1.xml

转载 作者:行者123 更新时间:2023-11-29 23:09:17 27 4
gpt4 key购买 nike

我想通过 ACTION_SEND 共享文件 /data/data/com.myapp/app_profiles/profile_1/games/game_1.xml

我已将其添加到 list 中:

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

我的filepaths.xml

<paths>
<files-path path="app_profiles/profile_1/games/" name="myGame" />
</paths>

代码(在 XYActivity 类中)是:

AlertDialog.Builder builder = new AlertDialog.Builder(this);    
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
....
File file = FileManager.getGameFile(gameID);
Uri fileUri = FileProvider.getUriForFile(XYActivity.this,
"com.myapp.fileprovider", file);

我收到以下错误:

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.myapp/app_profiles/profile_1/games/game_1.xml
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
...

我用文件浏览器检查过,这个文件确实存在!

关于我所知道的文件对象

file.getPath()         /data/user/0/com.myapp/app_profiles/profile_1/games/game_1.xml
file.getAbsolutePath() /data/user/0/com.myapp/app_profiles/profile_1/games/game_1.xml
file.getName() game_1.xml
file.getParent() /data/user/0/com.myapp/app_profiles/profile_1/games

对于 filepaths.xml 中的 path,我尝试了不同的值,甚至是错误的值:

path="app_profiles/profile_1/gamXes/"  
path="app_profiles/profile_1/games/"
path="app_profiles/profile_1/games"
path="profile_1/games"
path="games/"
path="games"
path="."
path="../games/"

这不会改变任何事情。这表明它们都错了,我只需要使用正确的值,但我不知道那会是什么/为什么我的值不起作用。

有几个类似的答案,但它们对我不起作用

没有子目录:FileProvider error "Failed to find configured root that contains /data/data/sawbodeployer.entm.illinois.edu ..."
外部存储:File Provider: Failed to find configured root that contains , java.lang.IllegalArgumentException: Failed to find configured root that contains , 还有很多

最佳答案

/data/data/com.myapp/app_profiles/profile_1/games/game_1.xml不是标准位置,FileProvider不支持它。 <files-path>用于 getFilesDir() ,这将映射到 /data/data/com.myapp/files/ ,并且您的文件不在其中。

或者:

  • 将文件存储在更好的位置(例如,getFilesDir() 以外的目录),或

  • 自己写ContentProvider可以从您想要的位置提供文件

关于java - 共享内部文件给出 : Failed to find configured root that contains/data/data/com. myapp/app_profiles/profile_1/games/game_1.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174261/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com