mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Merge pull request #306 from metaphore/qr-code-sharing-fix
Fix Share QR Code Crash
This commit is contained in:
commit
1e38621c57
@ -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)))
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user