diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScScannerActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScScannerActivity.kt index 17090b75d..03a9fd347 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScScannerActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScScannerActivity.kt @@ -20,26 +20,31 @@ class ScScannerActivity : BaseActivity() { fun importQRcode(): Boolean { RxPermissions(this) .request(Manifest.permission.CAMERA) - .subscribe { - if (it) + .subscribe { granted -> + if (granted) { scanQRCode.launch(Intent(this, ScannerActivity::class.java)) - else + } else { toast(R.string.toast_permission_denied) + } } - return true } + private val scanQRCode = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { if (it.resultCode == RESULT_OK) { - val (count, countSub) = AngConfigManager.importBatchConfig(it.data?.getStringExtra("SCAN_RESULT"), "", false) + val scanResult = it.data?.getStringExtra("SCAN_RESULT").orEmpty() + val (count, countSub) = AngConfigManager.importBatchConfig(scanResult, "", false) + if (count + countSub > 0) { toast(R.string.toast_success) } else { toast(R.string.toast_failure) } + startActivity(Intent(this, MainActivity::class.java)) } finish() } + }