fun subscribeWidgetMenuState(){ context.contentResolver.registerContentObserver( Settings.Secure.getUriFor("widget_menu_state"), true, object : ContentObserver(Handler()) { override fun onChange(selfChange: Boolean) { val widgetMenuState = Settings.Secure.getInt(contentResolver, "widget_menu_state") val widgetMenuXPosition = Settings.Secure.getInt(contentResolver, "widget_menu_x_position") Log.i(TAG, "onChange: widget_menu_state=$widgetMenuState, widget_menu_x_position=$widgetMenuXPosition") } }) } 将这段代码转换成java
时间: 2024-02-10 15:17:40 浏览: 33
以下是将 Kotlin 代码转换成 Java 代码后的实现:
```java
public void subscribeWidgetMenuState() {
getContentResolver().registerContentObserver(
Settings.Secure.getUriFor("widget_menu_state"),
true,
new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
int widgetMenuState = Settings.Secure.getInt(getContentResolver(),
"widget_menu_state");
int widgetMenuXPosition = Settings.Secure.getInt(getContentResolver(),
"widget_menu_x_position");
Log.i(TAG, "onChange: widget_menu_state=" + widgetMenuState
+ ", widget_menu_x_position=" + widgetMenuXPosition);
}
});
}
```
这段 Java 代码与 Kotlin 代码的功能是完全相同的,只是语法略有不同。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)