Я хочу управлять яркостью планшета. Мой код (сокращенно):
Код: Выделить всё
public class FullscreenActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val webView = findViewById(R.id.webView)
webView.addJavascriptInterface(WebAppInterface(this), "Android")
}
public fun jsmessage(message: String) {
val lp = this.window.attributes
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF
this.window.attributes = lp
}
}
public class WebAppInterface(mContext: Context) {
@JavascriptInterface
public fun message(data: String) {
Log.d("TAG", data)
((FullscreenActivity)mContext).jsmessage()
Подробнее здесь: [url]https://stackoverflow.com/questions/79338878/problem-to-get-the-context-of-activity-in-webappinterface-class[/url]