Problème 1: Je pdf stocké dansPartage de documents via l'intention/Fileprovider
Environment.getExternalStorageDirectory() --> /storage/emulated/0/appname/downloads/sample.pdf
Je te l'envoie en utilisant normalement comme indiqué:
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"));
Maintenant, le résultat est
Le problème est le partage de fichiers sans le nom de fichier.
Problème 2: Quand je suis en train d'utiliser le fournisseur de fichiers PDF ne partage pas me donne une erreur:
Unable to share. Please try again
Environment.getFilesDir() --> /data/data/com.myapp.name/files/myapp/downloads/sample.pdf
fichier Manifest:
<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);
Quelle est la meilleure façon de le faire?