From bcd1aeb0386a0bf86d5fdb37c0db6d5e95967689 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 5 Jul 2022 19:47:47 +0900 Subject: [PATCH] fix mic --- .../java/com/katahiromz/krakra_ja_jp/MainActivity.kt | 12 +++++++++--- .../com/katahiromz/krakra_ja_jp/MyWebChromeClient.kt | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/katahiromz/krakra_ja_jp/MainActivity.kt b/app/src/main/java/com/katahiromz/krakra_ja_jp/MainActivity.kt index 923b1f5..26e1eba 100644 --- a/app/src/main/java/com/katahiromz/krakra_ja_jp/MainActivity.kt +++ b/app/src/main/java/com/katahiromz/krakra_ja_jp/MainActivity.kt @@ -21,6 +21,7 @@ class MainActivity : AppCompatActivity(), ValueCallback, TextToSpeech.On } private var webView: WebView? = null + private var chromeClient: MyWebChromeClient? = null private var tts: TextToSpeech? = null private var webViewThread: WebViewThread? = null private var ttsThread: TtsThread? = null @@ -96,6 +97,11 @@ class MainActivity : AppCompatActivity(), ValueCallback, TextToSpeech.On if (grantResults.isNotEmpty()) { if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { logD("Not PERMISSION_GRANTED!") + } else { + val myRequest = chromeClient?.myRequest + if (myRequest != null) { + myRequest.grant(myRequest.resources) + } } } } @@ -132,7 +138,7 @@ class MainActivity : AppCompatActivity(), ValueCallback, TextToSpeech.On } }) - val chromeClient = MyWebChromeClient(this, object: MyWebChromeClient.Listener { + chromeClient = MyWebChromeClient(this, object: MyWebChromeClient.Listener { override fun onSpeech(text: String) { logD("onSpeech") theText = text @@ -140,7 +146,7 @@ class MainActivity : AppCompatActivity(), ValueCallback, TextToSpeech.On } }) webView?.webChromeClient = chromeClient - webView?.addJavascriptInterface(chromeClient, "android") + webView?.addJavascriptInterface(chromeClient!!, "android") webView?.loadUrl(getString(R.string.url)) } } @@ -176,7 +182,7 @@ class MainActivity : AppCompatActivity(), ValueCallback, TextToSpeech.On } if (settings != null) { val versionName = getVersionName() - updateUserAgent(settings!!, versionName) + updateUserAgent(settings, versionName) } } diff --git a/app/src/main/java/com/katahiromz/krakra_ja_jp/MyWebChromeClient.kt b/app/src/main/java/com/katahiromz/krakra_ja_jp/MyWebChromeClient.kt index a169409..35b0e86 100644 --- a/app/src/main/java/com/katahiromz/krakra_ja_jp/MyWebChromeClient.kt +++ b/app/src/main/java/com/katahiromz/krakra_ja_jp/MyWebChromeClient.kt @@ -27,9 +27,12 @@ class MyWebChromeClient(private val activity: AppCompatActivity, private val lis return activity.getString(resId) } + public var myRequest: PermissionRequest? = null + override fun onPermissionRequest(request: PermissionRequest?) { if (request == null) return + myRequest = request val permissionCheck = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) if (permissionCheck != PackageManager.PERMISSION_GRANTED) {