Use proper file URI for QR code sharing.

This commit is contained in:
Anton Chekulaev 2020-08-27 20:53:50 +10:00
parent 8705d8675b
commit fe1362187e
2 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -125,7 +126,7 @@ class ViewMyQRCodeFragment : Fragment() {
}
private fun shareQRCode() {
val directory = requireContext().externalCacheDir
val directory = requireContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
val fileName = "$hexEncodedPublicKey.png"
val file = File(directory, fileName)
file.createNewFile()
@ -137,7 +138,6 @@ class ViewMyQRCodeFragment : Fragment() {
fos.close()
val intent = Intent(Intent.ACTION_SEND)
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(requireActivity(), file))
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.type = "image/png"
startActivity(Intent.createChooser(intent, resources.getString(R.string.fragment_view_my_qr_code_share_title)))

View File

@ -14,8 +14,10 @@ public class FileProviderUtil {
private static final String AUTHORITY = "network.loki.securesms.fileprovider";
public static Uri getUriFor(@NonNull Context context, @NonNull File file) {
if (Build.VERSION.SDK_INT >= 24) return FileProvider.getUriForFile(context, AUTHORITY, file);
else return Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return FileProvider.getUriForFile(context, AUTHORITY, file);
else
return Uri.fromFile(file);
}
public static boolean isAuthority(@NonNull Uri uri) {