mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fix QR code sharing
This commit is contained in:
parent
7f0cda3b75
commit
23770f79a9
@ -1,5 +1,6 @@
|
|||||||
package org.thoughtcrime.securesms.loki.redesign.activities
|
package org.thoughtcrime.securesms.loki.redesign.activities
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
@ -14,6 +15,7 @@ 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 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
|
||||||
@ -129,21 +131,33 @@ class ViewMyQRCodeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareQRCode() {
|
private fun shareQRCode() {
|
||||||
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
fun proceed() {
|
||||||
val fileName = "$hexEncodedPublicKey.png"
|
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
||||||
val file = File(directory, fileName)
|
val fileName = "$hexEncodedPublicKey.png"
|
||||||
file.createNewFile()
|
val file = File(directory, fileName)
|
||||||
val fos = FileOutputStream(file)
|
file.createNewFile()
|
||||||
val size = toPx(240, resources)
|
val fos = FileOutputStream(file)
|
||||||
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false)
|
val size = toPx(240, resources)
|
||||||
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false)
|
||||||
fos.flush()
|
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
||||||
fos.close()
|
fos.flush()
|
||||||
val intent = Intent(Intent.ACTION_SEND)
|
fos.close()
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
val intent = Intent(Intent.ACTION_SEND)
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
||||||
intent.type = "image/png"
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
startActivity(Intent.createChooser(intent, "Share QR Code"))
|
intent.type = "image/png"
|
||||||
|
startActivity(Intent.createChooser(intent, "Share QR Code"))
|
||||||
|
}
|
||||||
|
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