2

画像リストがあり、選択した画像を共有したい.そのために、FileProviderを使用しました。Android 10でアプリを実行しています。また、shareIntent(Intent.EXTRA_STREAM,uri) なしで試してみた後、アプリを開くと、ダイアログを介してのみ共有されます。何も共有せずに、アプリを返すだけです。

AndroidManifest.xml で;

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_provider_paths" />
    </provider>

パスで;

<paths>
<files-path
    name="files"
    path="/" />
<cache-path
    name="cache"
    path="/" />

これが私がどのように使用し、意図を開始したかです。

 int pos = getAdapterPosition();

 File imageFile = new File(imageQuotes.get(pos).getPath());
 Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".provider", imageFile);

 Intent shareIntent = new Intent(Intent.ACTION_SEND);
 shareIntent.setDataAndType(uri,"image/*");
 shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
 mContext.startActivity(shareIntent);

つまり、WhatsAppを選択した後、アプリを実行します。画像ファイルが BIN ファイルとして送信され、whatsapp に画像プレビューがありません。uri は null ではなく、content://com.scoto.partestestapplication.provider/files/SavedImageQuotes/Partes_1601815401590 です

4

0 に答える 0