如何解决Android Java,FileProviders,getUriFromFile失败,并出现错误无法找到包含/storage/1018-2710/Pictures/Sarx7IIJi-o.jpg
因此,我一直试图通过电子邮件(或任何其他应用程序)发送图片。我使用MediaStore API将图片加载到我的应用中。我有他们的绝对路径/storage/1018-2710/Pictures/Sarx7IIJi-o.jpg
,但是当我尝试从他们那里获取Uri时,我收到一条错误消息,说 Failed to find configured root that contains /storage/1018-2710/Pictures/Sarx7IIJi-o.jpg
这是我的AppManifest
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.nikolam.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<Meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
还有我的file_paths.xml,我拥有所有这些条目,因此我可以尝试对其进行正确调试
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<external-files-path
name="external_files_pictures"
path="storage/1018-2710/Pictures/" />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
<external-media-path name="media" path="." />
<files-path name="my_images" path="images/"/>
</paths>
这是我尝试获取URI的地方
{
File myFile = new File(mviewmodel.selectedImages.get(0).getmImageUrl());
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(type);
Uri contentUri = getUriForFile(requireContext(),"com.nikolam.fileprovider",myFile);
sharingIntent.putExtra("android.intent.extra.STREAM",contentUri);
startActivity(Intent.createChooser(sharingIntent,"Share using"));
}
我尝试了许多不同的路径和配置,但到目前为止都没有奏效。
这是有问题的项目https://github.com/Nikola-Milovic/GalleryClone
之一解决方法
With cte as
(select T.restaurant_id,array_to_string(array_agg(food_id),',') as food_list
from
(select *
from Identifier t1
order by restaurant_id,food_id) T
group by T.restaurant_id)
select
--concat(r1.name,r2.name) as resturant_names,t1.restaurant_id as restaurant_id,r1.name as restaurant--,--t2.restaurant_id as restaurant_id2,--r2.name as restaurant_2,--t1.food_list as common_food_ids
from cte t1
join cte t2
on t1.restaurant_id = t2.restaurant_id
and t1.food_list = t2.food_list
left join Restaurants r1
on t1.restaurant_id = r1.restaurant_id
left join Restaurants r2
on t2.restaurant_id = r2.restaurant_id;
您的路径表明文件位于可移动Micro SD卡上。
不幸的是,FileProvider无法从可移动媒体提供文件。
您必须为此编写自己的ContentProvider。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。