Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何要求用户在不使用本机代码的情况下在NativeScript上启用蓝牙_Android_Ios_Bluetooth_Nativescript - Fatal编程技术网

Android 如何要求用户在不使用本机代码的情况下在NativeScript上启用蓝牙

Android 如何要求用户在不使用本机代码的情况下在NativeScript上启用蓝牙,android,ios,bluetooth,nativescript,Android,Ios,Bluetooth,Nativescript,我需要要求用户启用蓝牙,但我不想使用每个平台的本机方法,NativeScript中是否有标准化的方法 对于这种类型的请求,应该使用哪些类,以便代码能够与iOS和Android平台兼容,或者他们可能会想到的任何东西 对于iOS和Android,我需要这样的代码: DemoAppModel.prototype.doEnableBluetooth = function () { bluetooth.enable().then(function(enabled) { if(!enabl

我需要要求用户启用蓝牙,但我不想使用每个平台的本机方法,NativeScript中是否有标准化的方法

对于这种类型的请求,应该使用哪些类,以便代码能够与iOS和Android平台兼容,或者他们可能会想到的任何东西

对于iOS和Android,我需要这样的代码:

  DemoAppModel.prototype.doEnableBluetooth = function () {
    bluetooth.enable().then(function(enabled) {
   if(!enabled)
      setTimeout(function() {
    /* I need this code for iOS and Android */
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
      }, 500);
    });
  };

您可以使用nativescript蓝牙插件并使用:

顺便说一句,在Android上,您甚至可以通过编程在设备上启用蓝牙,它将通过使用以下命令征求用户的同意:


您好@Eddy Verbrugen,首先感谢您提供的插件,非常好,但不能与Bluetooth Classic配合使用。我更新问题。
bluetooth.isBluetoothEnabled().then(function(enabled) {
  // show an alert dialog or some nicer UI, if 'enabled' if false
});
bluetooth.enable().then(function(enabled) { /* .. */ });