问题
I am building an application using apache cordova, and I already can check if the bluetooth is available using the BluetoothSerial plugin.
If it is not then I redirect to a page where I have a button to call the device settings dialogue, but I cannot find any example of how to do this. Is it even possible?
I have found examples of getting the wifi / gps settings, but not the settings page itself.
回答1:
As far as I know you will need native code to call the bluetooth settings.
I'm assuming you know how to call java method from javascript. call this code
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 should open the bluetooth settings. See this for more details.
来源:https://stackoverflow.com/questions/27785674/how-can-i-open-the-settings-page-in-the-device-using-cordova