From 53a59762c3f4ecc860f2c82e5afc7dd9f2c7e309 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 10 Aug 2021 15:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt b/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt index 5bf92439c..9fd550b08 100644 --- a/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt @@ -5,13 +5,13 @@ import android.graphics.BitmapFactory import android.os.Bundle import android.view.Menu import android.view.MenuItem -import androidx.activity.result.contract.ActivityResultContracts import com.google.zxing.Result import com.king.zxing.CameraScan.OnScanResultCallback import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.databinding.ActivityQrcodeCaptureBinding import io.legado.app.utils.QRCodeUtils +import io.legado.app.utils.SelectImageContract import io.legado.app.utils.readBytes import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -19,8 +19,8 @@ class QrCodeActivity : BaseActivity(), OnScanResul override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate) - private val selectQrImage = registerForActivityResult(ActivityResultContracts.GetContent()) { - it?.readBytes(this)?.let { bytes -> + private val selectQrImage = registerForActivityResult(SelectImageContract()) { + it?.second?.readBytes(this)?.let { bytes -> val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) onScanResultCallback(QRCodeUtils.parseCodeResult(bitmap)) } @@ -41,7 +41,7 @@ class QrCodeActivity : BaseActivity(), OnScanResul override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.action_choose_from_gallery -> selectQrImage.launch("image/*") + R.id.action_choose_from_gallery -> selectQrImage.launch(null) } return super.onCompatOptionsItemSelected(item) }