Merge pull request #306 from metaphore/qr-code-sharing-fix

Fix Share QR Code Crash
This commit is contained in:
Niels Andriesse 2020-08-28 08:17:02 +10:00 committed by GitHub
commit 1e38621c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {