Skip to content

Commit

Permalink
fix mic
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Jul 5, 2022
1 parent 242360c commit bcd1aeb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/com/katahiromz/krakra_ja_jp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MainActivity : AppCompatActivity(), ValueCallback<String>, 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
Expand Down Expand Up @@ -96,6 +97,11 @@ class MainActivity : AppCompatActivity(), ValueCallback<String>, 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)
}
}
}
}
Expand Down Expand Up @@ -132,15 +138,15 @@ class MainActivity : AppCompatActivity(), ValueCallback<String>, TextToSpeech.On
}
})

val chromeClient = MyWebChromeClient(this, object: MyWebChromeClient.Listener {
chromeClient = MyWebChromeClient(this, object: MyWebChromeClient.Listener {
override fun onSpeech(text: String) {
logD("onSpeech")
theText = text
speechText(text)
}
})
webView?.webChromeClient = chromeClient
webView?.addJavascriptInterface(chromeClient, "android")
webView?.addJavascriptInterface(chromeClient!!, "android")
webView?.loadUrl(getString(R.string.url))
}
}
Expand Down Expand Up @@ -176,7 +182,7 @@ class MainActivity : AppCompatActivity(), ValueCallback<String>, TextToSpeech.On
}
if (settings != null) {
val versionName = getVersionName()
updateUserAgent(settings!!, versionName)
updateUserAgent(settings, versionName)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bcd1aeb

Please sign in to comment.