在Android上,我一直在尝试检索data_roaming和bluetooth_on,看看它们是否启用了。
我使用了以下代码:
Cursor cursorCheck = getContentResolver().query(
Settings.Global.CONTENT_URI,
new String[]{Settings.Global.BLUETOOTH_ON},
null, null, null);
assert cursorCheck != null;
cursorCheck.moveToFirst();
for (int i = 0; i < cursorCheck.getCount(); i++) {
Log.i("check1", cursorCheck.getString(0) + " ");
cursorCheck.moveToNext();
}
cursorCheck.close();但是,我得到了以下异常:
"java.lang.IllegalArgumentException: Invalid column: bluetooth_on“/ "java.lang.IllegalArgumentException: Invalid column: data_roaming”
https://developer.android.com/reference/android/provider/Settings.Global.html#DATA_ROAMING:https://developer.android.com/reference/android/provider/Settings.Global.html#BLUETOOTH_ON URL
谢谢
发布于 2020-09-20 16:11:13
代码中的问题是,Settings.Global.BLUETOOTH_ON不是列的名称,列的名称是name,bluetooth_on是该列中的值,所以当您像这样进行查询时:
Cursor cursorCheck = getContentResolver().query(
Settings.Global.CONTENT_URI,
null,
"name=?", new String[]{"bluetooth_on"}, null);这将搜索具有bluetooth_on值的name列,并为您提供结果。
对于多个字符串数组,像这样添加or,然后将想要的值添加到字符串数组中。
要使蓝牙处于开/关状态,请使用:
cursorCheck.getString(2)享受吧!
https://stackoverflow.com/questions/63976321
复制相似问题