Problem 1: Ich habe eine pdf inden Austausch von Dokumenten über Intent/Fileprovider
Environment.getExternalStorageDirectory() --> /storage/emulated/0/appname/downloads/sample.pdf
gespeichert ich es bin das Senden normaler Art und Weise wie abgebildet mit:
File iconsStoragePath = Environment.getExternalStorageDirectory();
final String selpath = iconsStoragePath.getAbsolutePath() + "/appname/downloads/";
Intent intent = new Intent(Intent.ACTION_SEND);
Uri selectedUri = Uri.parse(selpath + "/" + item.getFilename());
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, selectedUri);
startActivity(Intent.createChooser(intent, "Share File"));
Jetzt ist das Ergebnis
Das Problem ist Dateifreigabe ohne den Dateinamen.
Problem 2: Wenn ich versuche, die Datei-Provider die pdf zu verwenden ist mir nicht Sharing einen Fehler gibt:
Unable to share. Please try again
Environment.getFilesDir() --> /data/data/com.myapp.name/files/myapp/downloads/sample.pdf
Manifest-Datei:
<application>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
</application>
xml/nnf_provider_paths .xml
<?xml version="1.0" encoding="utf-8"?>
<files-path
name="root"
path="myapp/downloads" />
Code:
File path = new File(getFilesDir(), "downloads");
File file = new File(documentsPath + "/" + filename);
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), AUTHORITY, file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.setType("application/pdf");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
Was ist der bessere Weg?