Android app directory structure, email files from internal storage

I have a problem. I am currently saving PDF files in the internal repository / data / user / 0 / com.thatapp.myApp / files / JP_31072016065930.pdf

Reading it through the application is not a problem, so I am sure that it exists. Now I am trying to send the file by email. From the other questions and answers here, I understand that you need to use a file provider.

So I added the following to my manifest

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

@ xml / filepath contains

 <paths xmlns:android="http://schemas.android.com/apk/res/android"> <files-path name="my_pdf" path=""/> 

My email sending feature is below

 String[] TO = {""}; String[] CC = {""}; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); emailIntent.setType("text/plain"); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OTP:" + fileNmStr); emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here"); File file = new File(fileNmStr); Log.i("PDF FILE", fileNmStr); Uri contentUri = getUriForFile(this, "com.thatapp.fileprovider", file); emailIntent.putExtra(Intent.EXTRA_STREAM, contentUri); try { startActivity(Intent.createChooser(emailIntent, "Send mail...")); finish(); Toast.makeText(this, "Email Sent.", Toast.LENGTH_SHORT).show(); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(this, "There is no email client installed.", Toast.LENGTH_SHORT).show(); } 

The file is registered as / data / user / 0 / com.thatapp.contract / files / OTP_JP_31072016065930.pdf

When I run the code, I remove the exception

 java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.thatapp.myApp/files/OTP_JP_31072016065930.pdf 

So, if from what I understand / data / user / 0 / == / data / data /, then what causes the problem? Is my file path wrong? I also tried "files /" as the path to the file path, but had the same problem. Please help .... looking at the problem for 24 hours.

0
source share

Source: https://habr.com/ru/post/1263053/


All Articles