FileProviderを使うのが楽で、以下はFileProviderを使ってACTION_SENDで共有する例
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>
<paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."> <external-files-path name="external_files_path" path="."> <root-path name="external_files" path="/storage/"> </root-path></external-files-path></external-path></paths>
File file = new File(filesToSend.get(0)); Uri contentUri = FileProvider.getUriForFile(App.getContext(), App.getContext().getPackageName() + ".provider", file ); String mimeType = "audio/*"; Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType( "application/octet-stream"); intent.putExtra(Intent.EXTRA_STREAM, contentUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); App.getContext().startActivity(intent);
0 件のコメント:
コメントを投稿