Caused by: java.lang.SecurityException: Need BLUETOOTH permission

来源:互联网 发布:淘宝上找同款 编辑:程序博客网 时间:2024/05/17 21:42
package com.m31bluetoothprinter.m31printerdemo;import android.bluetooth.BluetoothDevice;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import com.iprt.xzc_pc.android_print_sdk.BluetoothDiscover;import com.iprt.xzc_pc.android_print_sdk.BluetoothPrinter;import com.m31bluetoothprinter.m31printerdemo.Const.MacConst;public class MainActivity extends AppCompatActivity {    private BluetoothDevice printer;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initDev();    }    private void initDev() {        printer = BluetoothDiscover.getPrinter(MacConst.BT_MAC);        if(printer!=null){            printer.createBond();        }        BluetoothPrinter bluetoothPrinter = new BluetoothPrinter(printer);        Log.d("hlhtest", "initDev:getPrinter "+bluetoothPrinter.toString());    }}

配置文件中配置蓝牙权限

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/><uses-permission android:name="android.permission.BLUETOOTH"/>
0 0