热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

phoneGap蓝牙设备链接打印操作插件

前台bluetooth.js*Copyright2013101.keyLicensedundertheApacheLicense,Version2.0(theLicense

前台 bluetooth.js

/*
Copyright 2013  101.key

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CO NDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/


var Bluetooth = function() {};


/**
* 判断蓝牙设备启用

* @param successCallback:true or false
* @param failureCallback:error message
*/
Bluetooth.prototype.isBTEnabled = function(successCallback, failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBTEnabled', []);
};

/**
* 启用蓝牙设备

* @param successCallback:true
* @param failureCallback:error message
*/
Bluetooth.prototype.enableBT = function(successCallback,failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'enableBT', []);
}

/**
* 禁用蓝牙设备

* @param successCallback:true
* @param failureCallback:error message
*/
Bluetooth.prototype.disableBT = function(successCallback,failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'disableBT', []);
}

/**
* 开始蓝牙设备搜索

* @param successCallback:JSONArray {'name':'address',...}
* @param failureCallback:error message
*/
Bluetooth.prototype.discoverDevices = function(successCallback, failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'discoverDevices', []);
}

/**
* 停止蓝牙设备搜索

* @param successCallback:true or false
* @param failureCallback:error message
*/
Bluetooth.prototype.stopDiscoverDevices = function(successCallback, failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'stopDiscoverDevices', []);
}

/**
* 蓝牙设备是否已绑定

* @param successCallback:true or false
* @param failureCallback:error message
* @param address:设备物理地址
*/
Bluetooth.prototype.isBoundBT = function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBoundBT', [address]);
};

/**
* 绑定蓝牙设备

* @param successCallback:true or false
* @param failureCallback:error message
* @param address:设备物理地址
*/
Bluetooth.prototype.boundBT = function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'boundBT', [address]);
};

/**
* 解除蓝牙设备绑定

* @param successCallback:true or false
* @param failureCallback:error message
*/
Bluetooth.prototype.unBoundBT = function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'unBoundBT', [address]);
};

/**
* 列出所有已绑定的蓝牙设备

* @param successCallback:JSONArray {'name':'address',...}
* @param failureCallback:error message
*/
Bluetooth.prototype.listBoundDevices = function(successCallback, failureCallback) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'listBoundDevices', []);
};

/**
* 蓝牙设备是否已链接

* @param successCallback:true
* @param failureCallback:error message
* @param address:设备物理地址
*/
Bluetooth.prototype.isCOnnect= function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isConnect', [address]);
};

/**
* 链接蓝牙设备

* @param successCallback:success message
* @param failureCallback:error message
* @param address:设备物理地址
*/
Bluetooth.prototype.cOnnect= function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'connect', [address]);
};

/**
* 解除蓝牙设备链接

* @param successCallback:success message
* @param failureCallback:error message
* @param address:设备物理地址
*/
Bluetooth.prototype.discOnnect= function(successCallback, failureCallback, address) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'disconnect', [address]);
};

/**
* 往蓝牙设备写字符串数据

* @param successCallback:success message
* @param failureCallback:error message
* @param address:设备物理地址
* @param message:要写入的数据
* @param encoding:数据编码格式
*/
Bluetooth.prototype.writeString = function(successCallback, failureCallback, address, message, encoding) {
  return cordova.exec(successCallback, failureCallback, 'BluetoothPlugin', 'writeString', [address,message,encoding]);
};

/**
* 往蓝牙设备写ASCII码数据

* @param address:设备物理地址
* @param ascii:要写入的ASCII码数据
*/
Bluetooth.prototype.writeASCII = function(address, ascii) {
  return cordova.exec(function(message) {
    //alert(message);
  }, 
  function(error) {
    // alert( 'Error: ' + error );
  },'BluetoothPlugin', 'writeASCII', [address,ascii]);
};

if(!window.plugins) {
  window.plugins = {};
}
if (!window.plugins.BluetoothPlugin) {
  window.plugins.BluetoothPlugin = new Bluetooth();
}

 

----------------------------------------------------------------------

后台BluetoothPlugin.java

/*
Copyright  2013.01 101.key

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.apache.cordova.plugin;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

public class BluetoothPlugin extends CordovaPlugin {

private static final String ACTION_IS_BT_ENABLED = "isBTEnabled"; // 蓝牙是否可用
private static final String ACTION_ENABLE_BT = "enableBT"; // 启用蓝牙
private static final String ACTION_DISABLE_BT = "disableBT";// 禁用蓝牙
private static final String ACTION_DISCOVERDEVICES = "discoverDevices"; // 搜索蓝牙设备
private static final String ACTION_STOP_DISCOVERDEVICES = "stopDiscoverDevices"; // 停止蓝牙设备搜索

private static final String ACTION_IS_BOUND_BT = "isBoundBT"; // 指定的蓝牙设备是否绑定
private static final String ACTION_BOUND_BT = "boundBT"; // 绑定蓝牙设备
private static final String ACTION_UNBOUND_BT = "unBoundBT"; // 解除蓝牙设备绑定
private static final String ACTION_LIST_BOUND_DEVICES = "listBoundDevices"; // 列出所有已绑定的蓝牙设备

private static final String ACTION_IS_COnNECT= "isConnect"; // 指定的蓝牙设备是否已链接
private static final String ACTION_COnNECT= "connect"; // 链接蓝牙设备
private static final String ACTION_DISCOnNECT= "disconnect"; // 断开蓝牙设备链接

private static final String ACTION_WRITE_STRING = "writeString"; // 往蓝牙设备写入字符串数据
private static final String ACTION_WRITE_ASCII = "writeASCII"; // 往蓝牙设备写入ASCII码数据

private BluetoothAdapter m_bluetoothAdapter = null; // 蓝牙适配器
private BPBroadcastReceiver m_bpBroadcastReceiver = null; // 广播状态接收者
private boolean m_discovering = false; // 是否正在搜索蓝牙
private boolean m_stateChanging = false; // 状态变化
private JSONArray m_discoveredDevices = null; //已发现的蓝牙设备
private JSONArray m_boundDevices = null; //已绑定的蓝牙设备
private Map bluetoothSocketMap = new HashMap(); //已链接的蓝牙设备socket映射(address to socket)

/**
* Constructor for Bluetooth plugin
*/
public BluetoothPlugin() {
  m_bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  m_bpBroadcastReceiver = new BPBroadcastReceiver();
}

/**
* Execute a bluetooth function
*/
@Override
public boolean execute(String action, JSONArray args,
final CallbackContext callbackContext) throws JSONException {
// Register for necessary bluetooth events
Log.d("BluetoothPlugin", "Action: " + action);

// Check if bluetooth is supported at all
if (m_bluetoothAdapter == null) {
callbackContext.error("No bluetooth adapter found");
return false;
} else {
if (ACTION_IS_BT_ENABLED.equals(action)) {
try {
boolean isEnabled = m_bluetoothAdapter.isEnabled();
callbackContext.success(isEnabled + "");
} catch (Exception Ex) {
Log.d("BluetoothPlugin", "Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}

} else if (ACTION_ENABLE_BT.equals(action)) {
if (!m_bluetoothAdapter.isEnabled()) {
m_stateChanging = true;
cordova.startActivityForResult(this, new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE), 1);
while (m_stateChanging) {
}
;
}
if (m_bluetoothAdapter.isEnabled()) {
callbackContext.success("true");
} else {
callbackContext.error("蓝牙设备启用失败!");
return false;
}
}
else if (ACTION_DISABLE_BT.equals(action)) {
if (!m_bluetoothAdapter.disable()
&& m_bluetoothAdapter.isEnabled()) {
callbackContext.error("蓝牙设备禁用失败!");
return false;
} else {
callbackContext.success("true");
}
} else if (ACTION_DISCOVERDEVICES.equals(action)) {
cordova.getActivity().registerReceiver(m_bpBroadcastReceiver,
new IntentFilter(BluetoothDevice.ACTION_FOUND));
cordova.getActivity().registerReceiver(
m_bpBroadcastReceiver,
new IntentFilter(
BluetoothAdapter.ACTION_DISCOVERY_STARTED));
cordova.getActivity().registerReceiver(
m_bpBroadcastReceiver,
new IntentFilter(
BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
cordova.getThreadPool().execute(new Runnable() {
public void run() {
m_discoveredDevices = new JSONArray();
if (m_bluetoothAdapter.isDiscovering()) {
m_bluetoothAdapter.cancelDiscovery();
}
if (!m_bluetoothAdapter.startDiscovery()) {
callbackContext.error("无法启动蓝牙搜索!");
} else {
Log.i("BluetoothPlugin", "Discovering devices...");
m_discovering = true;
// Wait for discovery to finish
while (m_discovering) {
}
Log.d("BluetoothPlugin", "DiscoveredDevices: "
+ m_discoveredDevices.length());
callbackContext.success(m_discoveredDevices);
}
}
});
} else if (ACTION_STOP_DISCOVERDEVICES.equals(action)) {
try {
boolean stopped = true;
Log.d("BluetoothPlugin",
"Stop Discovering Bluetooth Devices...");
if (m_bluetoothAdapter.isDiscovering()) {
Log.i("BluetoothPlugin", "Stop discovery...");
stopped = m_bluetoothAdapter.cancelDiscovery();
m_discovering = false;
}
callbackContext.success(stopped + "");
} catch (Exception Ex) {
Log.d("BluetoothPlugin", "Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}
}
else if (ACTION_IS_BOUND_BT.equals(action)) {
try {
String addressDevice = args.getString(0);
BluetoothDevice device = m_bluetoothAdapter.getRemoteDevice(addressDevice);
boolean state = false;
if (device != null && device.getBondState() == BluetoothDevice.BOND_BONDED)
state = true;
else
state = false;
Log.d("BluetoothPlugin", device.getName() + "["
+ device.getAddress() + "]isBound: " + state);
callbackContext.success(state + "");
} catch (Exception Ex) {
Log.d("BluetoothPlugin", ACTION_IS_BOUND_BT
+ " Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}
}
else if (ACTION_BOUND_BT.equals(action)) {
try {
String addressDevice = args.getString(0);
if (m_bluetoothAdapter.isDiscovering()) {
m_bluetoothAdapter.cancelDiscovery();
}
boolean paired = false;
BluetoothDevice device = m_bluetoothAdapter.getRemoteDevice(addressDevice);
if (device != null && device.getBondState() == BluetoothDevice.BOND_BONDED){
paired = true;
callbackContext.success(paired + "");
return true;
}
Log.d("BluetoothPlugin",
"start createBond with Bluetooth device with name "
+ device.getName() + " and address "
+ device.getAddress());
Method m = device.getClass().getMethod("createBond");
paired = (Boolean) m.invoke(device);
Log.d("BluetoothPlugin", "Returning " + "Result: " + paired);
callbackContext.success(paired + "");
} catch (Exception Ex) {
Log.d("BluetoothPlugin", "Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}
} else if (ACTION_UNBOUND_BT.equals(action)) {
try {
String addressDevice = args.getString(0);
if (m_bluetoothAdapter.isDiscovering()) {
m_bluetoothAdapter.cancelDiscovery();
}
BluetoothDevice device = m_bluetoothAdapter
.getRemoteDevice(addressDevice);
boolean unpaired = false;
Log.d("BluetoothPlugin",
"unBouding Bluetooth device with "
+ device.getName() + " and address "
+ device.getAddress());
Method m = device.getClass().getMethod("removeBond");
unpaired = (Boolean) m.invoke(device);
Log.d("BluetoothPlugin", ACTION_UNBOUND_BT + " Returning "
+ "Result: " + unpaired);
callbackContext.success(unpaired + "");
} catch (Exception Ex) {
Log.d("BluetoothPlugin", ACTION_UNBOUND_BT
+ " Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}
} else if (ACTION_LIST_BOUND_DEVICES.equals(action)) {
try {
Log.d("BluetoothPlugin", "Getting paired devices...");
m_boundDevices = new JSONArray();
Set pairedDevices = m_bluetoothAdapter
.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
Log.i("BluetoothPlugin",
device.getName() + " "
+ device.getAddress() + " "
+ device.getBondState());

if ((device.getName() != null)
&& (device.getBluetoothClass() != null)) {
try {
JSONObject deviceInfo = new JSONObject();
deviceInfo.put("name", device.getName());
deviceInfo.put("address",
device.getAddress());
m_boundDevices.put(deviceInfo);
} catch (JSONException e) {
Log.e("BluetoothPlugin", e.getMessage());
}

} else
Log.i("BluetoothPlugin",device.getName()
+ " Problems retrieving attributes. Device not added ");
}
}
Log.d("BluetoothPlugin", ACTION_LIST_BOUND_DEVICES
+ " Returning " + m_boundDevices.toString());
callbackContext.success(m_boundDevices);
} catch (Exception Ex) {
Log.d("BluetoothPlugin", ACTION_LIST_BOUND_DEVICES
+ " Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());
}

else if (ACTION_IS_CONNECT.equals(action)) {
String addressDevice = args.getString(0);
if (bluetoothSocketMap.containsKey(addressDevice)){
callbackContext.success("true");
}else{
Log.d("BluetoothPlugin", "设备未链接!");
callbackContext.error("设备未链接!");

}
else if (ACTION_CONNECT.equals(action)) {
try {
String addressDevice = args.getString(0);
if (bluetoothSocketMap.containsKey(addressDevice)){
Log.d("BluetoothPlugin", "该设备已链接,不再重新进行链接");
callbackContext.success("该设备已链接!");
return true;
}
Log.d("BluetoothPlugin", "Connecting...");
BluetoothDevice bluetoothDevice = m_bluetoothAdapter
.getRemoteDevice(addressDevice);

Method m = bluetoothDevice.getClass().getMethod(
"createRfcommSocket", new Class[] { int.class });
BluetoothSocket bluetoothSocket = (BluetoothSocket) m.invoke(
bluetoothDevice, 1);
try {
bluetoothSocket.connect();
} catch (IOException e) {
Log.d("BluetoothPlugin",
"connect fail: " + e.getMessage());
callbackContext.error("设备链接失败: " + e.getMessage());
return false;
}
bluetoothSocketMap.put(addressDevice, bluetoothSocket);
Log.d("BluetoothPlugin", addressDevice+ " 设备链接成功");
callbackContext.success("设备链接成功!");
} catch (Exception e) {
Log.e("BluetoothPlugin",
e.toString() + " / " + e.getMessage());
callbackContext.error("链接失败: " + e.getMessage());
}
} else if (ACTION_DISCONNECT.equals(action)) {
String addressDevice = args.getString(0);
if (bluetoothSocketMap.containsKey(addressDevice)){
BluetoothSocket bluetoothSocket = (BluetoothSocket)bluetoothSocketMap.get(addressDevice);
Log.d("BluetoothPlugin", addressDevice+"断开链接操作中...");
try {
bluetoothSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("BluetoothPlugin",
e.toString() + " / " + e.getMessage());
callbackContext.error("断开链接失败: " + e.getMessage());
return false;
}
bluetoothSocketMap.remove(addressDevice);
bluetoothSocket = null;
Log.d("BluetoothPlugin", addressDevice+"已成功断开链接");
callbackContext.success("已成功解除设备链接!");
}else{
Log.d("BluetoothPlugin", addressDevice+" 设备无可用链接可断开,请重新确认!");
callbackContext.success("该设备无可用链接可断开,请重新确认!");
}
} else if (ACTION_WRITE_STRING.equals(action)) {
if (m_bluetoothAdapter.isDiscovering()) {
m_bluetoothAdapter.cancelDiscovery();
}
try {
String addressDevice = args.getString(0);
final String message = args.getString(1);
final String encoding = args.getString(2);
if (!isReady(callbackContext, addressDevice)){
return false;
}
BluetoothSocket bluetoothSocket = (BluetoothSocket)bluetoothSocketMap.get(addressDevice);
Log.d("BluetoothPlugin", "开始写入数据:"+message);
OutputStream outputStream = bluetoothSocket
.getOutputStream();
byte[] bytes = message.getBytes(encoding);
outputStream.write(bytes);
Log.d("BluetoothPlugin", "写入数据成功");
callbackContext.success(message);

} catch (Exception Ex) {
Log.d("BluetoothPlugin", ACTION_WRITE_STRING
+ " Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());

} else if (ACTION_WRITE_ASCII.equals(action)) {
if (m_bluetoothAdapter.isDiscovering()) {
m_bluetoothAdapter.cancelDiscovery();
}
try {
String addressDevice = args.getString(0);
final String ascii = args.getString(1);

if (!isReady(callbackContext, addressDevice)){
return false;
}

BluetoothSocket bluetoothSocket = (BluetoothSocket)bluetoothSocketMap.get(addressDevice);

Log.d("BluetoothPlugin", "开始写入数据:"+ascii);
OutputStream outputStream = bluetoothSocket
.getOutputStream();
byte[] bytes = toASCII(ascii);
outputStream.write(bytes);

Log.d("BluetoothPlugin", "写入数据成功");
callbackContext.success(ascii);
} catch (Exception Ex) {
Log.d("BluetoothPlugin", ACTION_WRITE_ASCII
+ " Got Exception " + Ex.getMessage());
callbackContext.error(Ex.getMessage());

}else {
callbackContext.error("Action '" + action + "' not supported");
return false;
}
}
return true;
}

public void setDiscovering(boolean state) {
m_discovering = state;
}

/**
* Receives activity results
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 1) {
m_stateChanging = false;
}
}

@Override
public void onDestroy() {
// TODO Auto-generated method stub
Log.i("BluetoothPlugin", "onDestroy " + this.getClass());
cordova.getActivity().unregisterReceiver(m_bpBroadcastReceiver);
super.onDestroy();
}

/**
* Helper class for handling all bluetooth based events
*/
private class BPBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("BluetoothPlugin", "Action: " + action);
// Check if we found a new device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
try {
JSONObject deviceInfo = new JSONObject();
if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
deviceInfo.put("name", bluetoothDevice.getName()
+ "(已绑定)");
} else {
deviceInfo.put("name", bluetoothDevice.getName());
}
deviceInfo.put("address", bluetoothDevice.getAddress());
m_discoveredDevices.put(deviceInfo);
Log.i("BluetoothPlugin",
"Device[" + bluetoothDevice.getName() + " "
+ bluetoothDevice.getAddress()
+ "] add to discoveredDevices");
} catch (JSONException e) {
Log.e("BluetoothPlugin", e.getMessage());
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.i("BluetoothPlugin", "Discovery started");
setDiscovering(true);
}
// Check if we finished discovering devices
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.i("BluetoothPlugin", "Discovery finished");
setDiscovering(false);
}
}
};

/**
* 开始写数据前,相关前置条件是否准备好
* @param callbackContext
* @param addressDevice
* @return
*/
private boolean isReady(CallbackContext callbackContext, String addressDevice){
if (!m_bluetoothAdapter.isEnabled()){
Log.d("BluetoothPlugin", "m_bluetoothAdapter isEnabled 不可用,无法写入.");
callbackContext.error("蓝牙适配器暂不能用,无法写入数据!");
return false;
}

BluetoothDevice bluetoothDevice = m_bluetoothAdapter
.getRemoteDevice(addressDevice);

if (bluetoothDevice == null){//找不到设备
Log.d("BluetoothPlugin", "系统找不到蓝牙设备,无法写入.");
callbackContext.error("系统找不到蓝牙设备,无法写入数据!");
return false;
}

if (bluetoothDevice.getBondState() != BluetoothDevice.BOND_BONDED){//已绑定链接
Log.d("BluetoothPlugin", "该设备未绑定,无法写入.");
callbackContext.error("该设备未绑定,无法写入数据!");
return false;
}

if (!bluetoothSocketMap.containsKey(addressDevice)){
Log.d("BluetoothPlugin", "该设备未链接,无法写入.");
callbackContext.error("该设备未链接,无法写入数据!");
return false;
}

return true;
}

private byte[] toASCII(String ascii) {
try {
String[] as = ascii.split(",");
byte[] bytes = new byte[as.length];
for (int i = 0; i bytes[i] = (byte) Integer.parseInt(as[i]);
}
return bytes;
} catch (Exception e) {
Log.d("BluetoothPlugin", "Invalid ASCII code.");
return null;
}
}

}

--------------------------------------------------------

页面调用

function writeString() {
window.plugins.BluetoothPlugin.writeASCII(
'设备MAC地址',
'27,64'  //蓝牙打印设备状态重置、初始化
);
window.plugins.BluetoothPlugin.writeString(
function(message) {
alert(message);
}, 
function(error) {
alert( 'Error: ' + error );
},
'设备MAC地址',
$('#msg').val(),
'GBK'
);
window.plugins.BluetoothPlugin.writeASCII(
'设备MAC地址',
'10,10,10,10' //换行打印
);
}

 


推荐阅读
  • Android日历提醒软件开源项目分享及使用教程
    本文介绍了一款名为Android日历提醒软件的开源项目,作者分享了该项目的代码和使用教程,并提供了GitHub项目地址。文章详细介绍了该软件的主界面风格、日程信息的分类查看功能,以及添加日程提醒和查看详情的界面。同时,作者还提醒了读者在使用过程中可能遇到的Android6.0权限问题,并提供了解决方法。 ... [详细]
  • CentOS7.8下编译muduo库找不到Boost库报错的解决方法
    本文介绍了在CentOS7.8下编译muduo库时出现找不到Boost库报错的问题,并提供了解决方法。文章详细介绍了从Github上下载muduo和muduo-tutorial源代码的步骤,并指导如何编译muduo库。最后,作者提供了陈硕老师的Github链接和muduo库的简介。 ... [详细]
  • 在一对一直播源码使用过程中,有时会出现软键盘切换闪屏问题,就是当切换表情的时候屏幕会跳动,因此要对一对一直播源码表情面板无缝切换进行优化。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 本文介绍了Sencha Touch的学习使用心得,主要包括搭建项目框架的过程。作者强调了使用MVC模式的重要性,并提供了一个干净的引用示例。文章还介绍了Index.html页面的作用,以及如何通过链接样式表来改变全局风格。 ... [详细]
  • Jquery 跨域问题
    为什么80%的码农都做不了架构师?JQuery1.2后getJSON方法支持跨域读取json数据,原理是利用一个叫做jsonp的概念。当然 ... [详细]
  • 1简介本文结合数字信号处理课程和Matlab程序设计课程的相关知识,给出了基于Matlab的音乐播放器的总体设计方案,介绍了播放器主要模块的功能,设计与实现方法.我们将该设 ... [详细]
  • 生产环境下JVM调优参数的设置实例
     正文前先来一波福利推荐: 福利一:百万年薪架构师视频,该视频可以学到很多东西,是本人花钱买的VIP课程,学习消化了一年,为了支持一下女朋友公众号也方便大家学习,共享给大家。福利二 ... [详细]
author-avatar
想要铭记的总是轻易忘却-
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有