mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 17:38:26 +00:00
Merge pull request #300 from metaphore/qr-code-share-fix
Fix Share QR Code Crash
This commit is contained in:
commit
a0b2f5dfb5
@ -340,12 +340,13 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
|||||||
|
|
||||||
private InputStream openFileUri(Uri uri) throws IOException {
|
private InputStream openFileUri(Uri uri) throws IOException {
|
||||||
FileInputStream fin = new FileInputStream(uri.getPath());
|
FileInputStream fin = new FileInputStream(uri.getPath());
|
||||||
int owner = FileUtils.getFileDescriptorOwner(fin.getFD());
|
//TODO Remove the commented code if there are no issues with reading shared files on October 2020
|
||||||
|
// int owner = FileUtils.getFileDescriptorOwner(fin.getFD());
|
||||||
|
|
||||||
if (owner == -1 || owner == Process.myUid()) {
|
// if (owner == -1 || owner == Process.myUid()) {
|
||||||
fin.close();
|
// fin.close();
|
||||||
throw new IOException("File owned by application");
|
// throw new IOException("File owned by application");
|
||||||
}
|
// }
|
||||||
|
|
||||||
return fin;
|
return fin;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package org.thoughtcrime.securesms.loki.activities
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.fragment.app.FragmentPagerAdapter
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.tbruyelle.rxpermissions2.RxPermissions
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentPagerAdapter
|
||||||
import kotlinx.android.synthetic.main.activity_qr_code.*
|
import kotlinx.android.synthetic.main.activity_qr_code.*
|
||||||
import kotlinx.android.synthetic.main.fragment_view_my_qr_code.*
|
import kotlinx.android.synthetic.main.fragment_view_my_qr_code.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
@ -106,8 +104,8 @@ class ViewMyQRCodeFragment : Fragment() {
|
|||||||
|
|
||||||
private val hexEncodedPublicKey: String
|
private val hexEncodedPublicKey: String
|
||||||
get() {
|
get() {
|
||||||
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context!!)
|
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext())
|
||||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context!!)
|
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext())
|
||||||
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
|
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,33 +125,22 @@ class ViewMyQRCodeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareQRCode() {
|
private fun shareQRCode() {
|
||||||
fun proceed() {
|
val directory = requireContext().externalCacheDir
|
||||||
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
val fileName = "$hexEncodedPublicKey.png"
|
||||||
val fileName = "$hexEncodedPublicKey.png"
|
val file = File(directory, fileName)
|
||||||
val file = File(directory, fileName)
|
file.createNewFile()
|
||||||
file.createNewFile()
|
val fos = FileOutputStream(file)
|
||||||
val fos = FileOutputStream(file)
|
val size = toPx(280, resources)
|
||||||
val size = toPx(280, resources)
|
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false, false)
|
||||||
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false, false)
|
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
||||||
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
fos.flush()
|
||||||
fos.flush()
|
fos.close()
|
||||||
fos.close()
|
val intent = Intent(Intent.ACTION_SEND)
|
||||||
val intent = Intent(Intent.ACTION_SEND)
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(requireActivity(), file))
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
intent.type = "image/png"
|
intent.type = "image/png"
|
||||||
startActivity(Intent.createChooser(intent, resources.getString(R.string.fragment_view_my_qr_code_share_title)))
|
startActivity(Intent.createChooser(intent, resources.getString(R.string.fragment_view_my_qr_code_share_title)))
|
||||||
}
|
|
||||||
if (RxPermissions(this).isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
proceed()
|
|
||||||
} else {
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
val unused = RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe { isGranted ->
|
|
||||||
if (isGranted) {
|
|
||||||
proceed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
Loading…
x
Reference in New Issue
Block a user