[英]provider on /storage/emulated/0/
I know this is an oldie, but I do not seem to find a way to manage it...我知道这是一个老歌,但我似乎没有找到管理它的方法......
I've to capture a Camera image for later IO processing, transferring it to a network share, but I fail lot before this... after some reading here, I found the way to actually do it on KitKat checking the running SDK, and it works.. but, now I'm testing it on a Nougat device as well..我必须捕获相机图像以供以后的 IO 处理,将其传输到网络共享,但在此之前我失败了很多……阅读此处后,我找到了在 KitKat 检查正在运行的 SDK 上实际执行此操作的方法,并且它有效..但是,现在我也在牛轧糖设备上测试它..
for Nougat I've read a provider should be used, and I'm trying to...对于牛轧糖,我读过应该使用提供程序,我正在尝试......
the captured image MUST be stored in a particular folder which is捕获的图像必须存储在特定文件夹中
"/storage/emulated/0/InsulinPower/amSignTool/Data" “/storage/emulated/0/InsulinPower/amSignTool/Data”
for later IO processing... so I think something similar to must be used, currently with no look..用于以后的 IO 处理......所以我认为必须使用类似的东西,目前没有外观..
I had a look at provider definition for all "area", but can not get the answer I need and more I get exceptions.. as defining the retrival URI I get我查看了所有“区域”的提供者定义,但无法得到我需要的答案,而且我得到了更多的异常......作为定义我得到的检索 URI
java.lang.reflect.InvocationTargetException java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/InsulinPower/amSignTool/Data/XCAMX-201805171828082115829615.jpg java.lang.IllegalArgumentException:无法找到包含 /storage/emulated/0/InsulinPower/amSignTool/Data/XCAMX-201805171828082115829615.jpg 的配置根
in the file_paths I tried quiet everything, as you can see... but it only works if I do refer external-path and NOT external-path-files , which indeed seems to be the one I need..external-path the code is trivial....在 file_paths 中,我尝试了安静的一切,正如您所看到的...但它仅在我确实引用external-path而不是external-path-files时才有效,这确实似乎是我需要的那个..external-path 代码是微不足道的....
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
File pictureFile = null;
try {
pictureFile = GENERIC.amPictureFile(this);
} catch (IOException ex) {
// Error occurred while creating the File
Toast.makeText(this, "Create file failed!", Toast.LENGTH_SHORT).show();
}
if (pictureFile != null) {
//https://stackoverflow.com/questions/40087944/content-uri-crashes-camera-on-android-kitkat
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT){
this.imageToUploadUri = Uri.fromFile(pictureFile);
} else {
this.imageToUploadUri = FileProvider.getUriForFile(this,"com.insulinpower.android.fileprovider", pictureFile); // <-- THIS statement crashes with the indicated exception
}
//\ https://stackoverflow.com/questions/40087944/content-uri-crashes-camera-on-android-kitkat
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
// file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Share folder under public external storage folder.The base folder is Environment.getExternalStorageDirectory()-->
<!--external-path name="my_data" path="InsulinPower/amSignTool/Data/" /> -->
<external-files-path name="my_data" path="/InsulinPower/amSignTool/Data/" />
<!-- external-files-path name="my_data" path="InsulinPower/amSignTool/Data/" / -->
<!-- external-files-path name="my_data" path="/" /-->
</paths>
// manifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.insulinpower.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
File storageDir = new File(Environment.getExternalStorageDirectory(),""); File storageDir = new File(Environment.getExternalStorageDirectory(),"");
returns "/storage/emulated/0" // valid, adding the /InsulinPower/amSignTool/Data suffix to go to the correct folder...返回 "/storage/emulated/0" // 有效,添加 /InsulinPower/amSignTool/Data 后缀以转到正确的文件夹...
File file = this.getExternalFilesDir(null);文件文件 = this.getExternalFilesDir(null);
returns "/storage/emulated/0/Android/data/com.insulinpower.amsigntool/files" // not valid for me返回“/storage/emulated/0/Android/data/com.insulinpower.amsigntool/files”//对我无效
any hint would be really appreciated to understand my errors, and please excuse my poor english..任何提示都将非常感谢理解我的错误,请原谅我糟糕的英语..
TIA TIA
Andrea安德烈亚
the captured image MUST be stored in a particular folder which is "/storage/emulated/0/InsulinPower/amSignTool/Data"捕获的图像必须存储在“/storage/emulated/0/InsulinPower/amSignTool/Data”的特定文件夹中
That is new File(Environment.getExternalStorageDirectory(), "InsulinPower/amSignTool/Data")
.那是new File(Environment.getExternalStorageDirectory(), "InsulinPower/amSignTool/Data")
。
but it only works if I do refer external-path and NOT external-path-files, which indeed seems to be the one I need但它只有在我确实引用外部路径而不是外部路径文件时才有效,这似乎确实是我需要的
Correct.正确的。 Try:尝试:
<external-path name="my_data" path="/InsulinPower/amSignTool/Data/" />
You definitely want <external-path>
, not <external-files-path>
, given where you want the file to go.你肯定想要<external-path>
,而不是<external-files-path>
,因为你想要文件去哪里。
You also need:您还需要:
cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
before you start the activity.在您开始活动之前。 Otherwise, the camera app has no rights to write to this location.否则,相机应用程序无权写入此位置。
@CommonsWare: wow... thank's it works... @CommonsWare:哇...谢谢它的工作原理...
I just had to modify my pictureFile = GENERIC.amPictureFile(this);我只需要修改我的图片文件 = GENERIC.amPictureFile(this);
to set the referencing module StringFileName to start as将引用模块 StringFileName 设置为开始
this.m_PictureFilePath = "file:" + pictureFile.getAbsolutePath();
as I did not started it with "file:" as well...因为我也没有用“文件:”开始它......
and as GENERIC.amPictureFile(this) already points to Environment.getExternalStorageDirectory() + "/Insulin...../"并且因为 GENERIC.amPictureFile(this) 已经指向 Environment.getExternalStorageDirectory() + "/Insulin...../"
I had to modify我不得不修改
<external-path name="my_data" path="/InsulinPower/amSignTool/Data/" />
to到
<external-path name="my_data" path="." />
as I think to understand the file creation already points to a sub-folder of the root, and having it doubbled in provider and in file creation should sub-nest the folding... or this is my understanding..因为我认为要理解文件创建已经指向根目录的子文件夹,并且在提供程序和文件创建中将它加倍应该对折叠进行子嵌套......或者这是我的理解..
https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en helped as well... https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en 也有帮助......
thank you so much, you were very helpful indeed... really appreciated 'couse I just start to understand this fileprovider stuff非常感谢,你确实很有帮助......真的很感激,因为我刚刚开始了解这个文件提供者的东西
Andrea安德烈亚
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.