“failed to find configured root that contains”错误的原因是什么?

huangapple go评论119阅读模式
英文:

How can I find the cause of the error: "failed to find configured root that contains"

问题

我有一个错误,但找不到它的原因。生成Uri时出错。

我查看了几个关于这个主题的帖子,这里讨论过。但是,错误无法纠正。我认为某处可能有拼写错误。我该如何找到我错在哪里?

  1. var
  2. files: Tfile;
  3. lIntent: JIntent;
  4. lJRecipient: TJavaObjectArray<JString>;
  5. lURI: Jnet_Uri;
  6. LAuthority: JString;
  7. lJFile: JFile;
  8. lFileName: string;
  9. lFilePath: string;
  10. lFilePathFileName: string;
  11. Surf : TBitmapSurface;
  12. begin
  13. lFileName := Concat('Foto','Code' ,'.jpg') ;
  14. lFilePath := System.IOUtils.TPath.GetPublicPath;
  15. lFilePathFileName := System.IOUtils.Tpath.Combine(lFilePath, lFileName) ;
  16. Surf:=TBitMapSurface.Create;
  17. SaveParams.Quality:=100;
  18. try
  19. Surf.Assign(imResult.Bitmap);
  20. TbitMapCodecManager.SaveToFile(lFilePathFileName, Surf, @SaveParams);
  21. finally
  22. Surf.Free;
  23. end;
  24. lIntent:= TJIntent.Create;
  25. lIntent.setType(StringToJString('message/rfc822'));
  26. lIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
  27. lIntent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  28. lIntent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, lJRecipient);
  29. lIntent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString('Text'));
  30. lIntent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString('.....'));
  31. LAuthority := StringToJString(JStringToString(
  32. TAndroidHelper.Context.getApplicationContext.getPackageName)+'.fileprovider');
  33. lJFile:= TJFile.JavaClass.init(StringToJString(lFileName));
  34. lUri := TJFileProvider.JavaClass.getUriForFile(
  35. TAndroidHelper.Context, LAuthority, lJFile);

我已在清单文件中包含了以下内容

  1. <provider
  2. android:name="android.support.v4.content.FileProvider"
  3. android:authorities="com.embarcadero.ScanDecoder.fileprovider"
  4. android:grantUriPermissions="true"
  5. android:exported="false">
  6. <meta-data
  7. android:name="android.support.FILE_PROVIDER_PATHS"
  8. android:resource="@xml/filepaths" />
  9. </provider>

创建了一个文件 \res\xml\filepaths.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <paths xmlns:android="http://schemas.android.com/apk/res/android">
  3. <files-path name="MyFoto" path="."/>
  4. </paths>

我尝试将文件中的路径更改为以下内容,但仍然出现此错误。

  1. path="."
  2. path="./"
  3. path="files/"
  4. path=".files/"

我哪里错了?

英文:

I have an error and I can't find the cause of it. Error while generating Uri.

I looked through several topics on this topic, which were discussed here. However, the error could not be corrected. I think there is a typo somewhere. How can I find where I am wrong?

  1. var
  2. files: Tfile;
  3. lIntent: JIntent;
  4. lJRecipient: TJavaObjectArray&lt;JString&gt;;
  5. lURI: Jnet_Uri;
  6. LAuthority: JString;
  7. lJFile: JFile;
  8. lFileName: string;
  9. lFilePath: string;
  10. lFilePathFileName: string;
  11. Surf : TBitmapSurface;
  12. begin
  13. lFileName := Concat(&#39;Foto&#39;,&#39;Code&#39; ,&#39;.jpg&#39;) ;
  14. lFilePath := System.IOUtils.TPath.GetPublicPath;
  15. lFilePathFileName := System.IOUtils.Tpath.Combine(lFilePath, lFileName) ;
  16. Surf:=TBitMapSurface.Create;
  17. SaveParams.Quality:=100;
  18. try
  19. Surf.Assign(imResult.Bitmap);
  20. TbitMapCodecManager.SaveToFile(lFilePathFileName, Surf, @SaveParams);
  21. finally
  22. Surf.Free;
  23. end;
  24. lIntent:= TJIntent.Create;
  25. lIntent.setType(StringToJString(&#39;message/rfc822&#39;));
  26. lIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
  27. lIntent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  28. lIntent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, lJRecipient);
  29. lIntent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(&#39;Text&#39;));
  30. lIntent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(&#39;.....&#39;));
  31. LAuthority := StringToJString(JStringToString(
  32. TAndroidHelper.Context.getApplicationContext.getPackageName)+&#39;.fileprovider&#39;);
  33. lJFile:= TJFile.JavaClass.init(StringToJString(lFileName));
  34. lUri := TJFileProvider.JavaClass.getUriForFile(
  35. TAndroidHelper.Context, LAuthority, lJFile);

I have included in the manifest file

  1. &lt;provider
  2. android:name=&quot;android.support.v4.content.FileProvider&quot;
  3. android:authorities=&quot;com.embarcadero.ScanDecoder.fileprovider&quot;
  4. android:grantUriPermissions=&quot;true&quot;
  5. android:exported=&quot;false&quot;&gt;
  6. &lt;meta-data
  7. android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
  8. android:resource=&quot;@xml/filepaths&quot; /&gt;
  9. &lt;/provider&gt;

Created a file \res\xml\filepaths.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;paths xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
  3. &lt;files-path name=&quot;MyFoto&quot; path=&quot;.&quot;/&gt;
  4. &lt;/paths&gt;

I tried changing the path in the file to the following. I am still getting this error.

  1. path=&quot;.&quot;
  2. path=&quot;./&quot;
  3. path=&quot;files/&quot;
  4. path=&quot;.files/&quot;

Where have I gone wrong?

答案1

得分: 1

@Dave Nottage建议的正确方法是使用FileProvider一起工作。
当您在项目选项的权限列表中启用“安全文件共享”选项时,xml清单和提供程序路径会自动生成。
现在它可以工作。
我提供一个有效的解决方案。

  1. procedure TestSendEmail();
  2. {$IF DEFINED(ANDROID)}
  3. var
  4. lIntent: JIntent;
  5. lJRecipient: TJavaObjectArray&lt;JString&gt;;
  6. lURI: Jnet_Uri;
  7. lFileName: string;
  8. lFilePath: string;
  9. lFilePathFileName: string;
  10. Delim :Char;
  11. // Surf : TBitmapSurface;
  12. {$ENDIF}
  13. begin
  14. lFileName := Concat('MyFile' ,'.jpg') ;
  15. lFilePath := System.IOUtils.TPath.GetPublicPath ;
  16. lFilePathFileName := System.IOUtils.Tpath.Combine(lFilePath, lFileName) ;
  17. Surf:=TBitMapSurface.Create;
  18. SaveParams.Quality:=100;
  19. try
  20. Surf.Assign(imResult.Bitmap);
  21. // Save file
  22. TbitMapCodecManager.SaveToFile(lFilePathFileName, Surf, @SaveParams);
  23. finally
  24. Surf.Free;
  25. end;
  26. {$IF DEFINED(ANDROID)}
  27. lJRecipient:= TJavaObjectArray&lt;JString&gt;.Create(1);
  28. lJRecipient.Items[0]:= StringToJString('xxxxxxx@yyyy.com');
  29. lIntent:= TJIntent.Create;
  30. lIntent.setType(StringToJString('message/rfc822'));
  31. lIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
  32. lIntent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  33. lIntent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, lJRecipient);
  34. lIntent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString('Subj'));
  35. lIntent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString('Text'));
  36. lUri:= TAndroidHelper.JFileToJURI(
  37. TJFile.JavaClass.init(StringToJString(lFilePathFileName)));
  38. lIntent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,TJParcelable.Wrap(lUri)) ;
  39. try
  40. TAndroidHelper.Activity.startActivity(lIntent);
  41. except
  42. on E: Exception do
  43. begin
  44. ShowMessage( E.Message);
  45. end;
  46. end;
  47. {$ENDIF}
  48. end;

这是您提供的代码的翻译部分。

英文:

@Dave Nottage suggested the correct way to work with FileProvider.
The xml manifest and provider paths are generated automatically when you enable the "Secure File Sharing" option in the list of rights in the project options.
Now it works.
I provide a working solution.

  1. procedure TestSendEmail();
  2. {$IF DEFINED(ANDROID)}
  3. var
  4. lIntent: JIntent;
  5. lJRecipient: TJavaObjectArray&lt;JString&gt;;
  6. lURI: Jnet_Uri;
  7. lFileName: string;
  8. lFilePath: string;
  9. lFilePathFileName: string;
  10. Delim :Char;
  11. // Surf : TBitmapSurface;
  12. {$ENDIF}
  13. begin
  14. lFileName := Concat(&#39;MyFile&#39; ,&#39;.jpg&#39;) ;
  15. lFilePath := System.IOUtils.TPath.GetPublicPath ;
  16. lFilePathFileName := System.IOUtils.Tpath.Combine(lFilePath, lFileName) ;
  17. Surf:=TBitMapSurface.Create;
  18. SaveParams.Quality:=100;
  19. try
  20. Surf.Assign(imResult.Bitmap);
  21. // Save file
  22. TbitMapCodecManager.SaveToFile(lFilePathFileName, Surf, @SaveParams);
  23. finally
  24. Surf.Free;
  25. end;
  26. {$IF DEFINED(ANDROID)}
  27. lJRecipient:= TJavaObjectArray&lt;JString&gt;.Create(1);
  28. lJRecipient.Items[0]:= StringToJString(&#39;xxxxxxx@yyyy.com&#39;);
  29. lIntent:= TJIntent.Create;
  30. lIntent.setType(StringToJString(&#39;message/rfc822&#39;));
  31. lIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
  32. lIntent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  33. lIntent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, lJRecipient);
  34. lIntent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(&#39;Subj&#39;));
  35. lIntent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(&#39;Text&#39;));
  36. lUri:= TAndroidHelper.JFileToJURI(
  37. TJFile.JavaClass.init(StringToJString(lFilePathFileName)));
  38. lIntent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,TJParcelable.Wrap(lUri)) ;
  39. try
  40. TAndroidHelper.Activity.startActivity(lIntent);
  41. except
  42. on E: Exception do
  43. begin
  44. ShowMessage( E.Message);
  45. end;
  46. end;
  47. {$ENDIF}
  48. end;

huangapple
  • 本文由 发表于 2023年5月29日 21:10:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定