【发布时间】:2015-01-05 18:32:02
【问题描述】:
我正在使用 apache cordova 构建一个应用程序,并且我已经可以使用 the BluetoothSerial plugin 检查蓝牙是否可用。
如果不是,我会重定向到一个页面,在该页面上我有一个按钮来调用设备设置对话框,但我找不到任何如何执行此操作的示例。有可能吗?
我找到了获取 wifi / gps 设置的示例,但没有找到设置页面本身。
【问题讨论】:
我正在使用 apache cordova 构建一个应用程序,并且我已经可以使用 the BluetoothSerial plugin 检查蓝牙是否可用。
如果不是,我会重定向到一个页面,在该页面上我有一个按钮来调用设备设置对话框,但我找不到任何如何执行此操作的示例。有可能吗?
我找到了获取 wifi / gps 设置的示例,但没有找到设置页面本身。
【问题讨论】:
据我所知,您需要本机代码来调用蓝牙设置。
我假设您知道如何从 javascript 调用 java 方法。调用此代码
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.settings",
"com.android.settings.bluetoothSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);
这应该会打开蓝牙设置。详情请见this。
【讨论】: