蓝牙权限android级别,在Android中请求多个蓝牙权限棉花糖

我正在开发一个连接应用程序,该应用程序连接到带有编译的SDK 23的蓝牙设备。我在申请蓝牙多重权限时遇到问题。这是我迄今所做的:在Android中请求多个蓝牙权限棉花糖

@Override

public void onStart() {

super.onStart();

if (D)

Log.e(TAG, "++ ON START ++");

if (ContextCompat.checkSelfPermission(MyBlueToothClientActivity.this,

Manifest.permission.BLUETOOTH)

!= PackageManager.PERMISSION_GRANTED) {

} else {

ActivityCompat.requestPermissions(MyBlueToothClientActivity.this,

new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN},

REQUEST_ENABLE_BT);

}

if (ContextCompat.checkSelfPermission(MyBlueToothClientActivity.this,

Manifest.permission.BLUETOOTH)

!= PackageManager.PERMISSION_GRANTED) {

} else {

ActivityCompat.requestPermissions(MyBlueToothClientActivity.this,

new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN},

REQUEST_CONNECT_DEVICE_INSECURE);

}

}

@Override

public void onRequestPermissionsResult(int requestCode,

String permissions[], int[] grantResults) {

switch (requestCode) {

case REQUEST_ENABLE_BT: {

// If request is cancelled, the result arrays are empty.

if (grantResults.length > 0

&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay!

Intent enableIntent = new Intent(

BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableIntent, REQUEST_ENABLE_BT);

} else {

// permission denied, boo! Disable the

// functionality that depends on this permission.

if (CommonData.mChatService == null)

setupChat();

Toast.makeText(MyBlueToothClientActivity.this, "Permission denied for bluetooth", Toast.LENGTH_SHORT).show();

}

return;

}

case REQUEST_CONNECT_DEVICE_INSECURE: {

// If request is cancelled, the result arrays are empty.

if (grantResults.length > 0

&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay!

Intent enableIntent = new Intent(

BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableIntent, REQUEST_CONNECT_DEVICE_INSECURE);

} else {

// permission denied, boo! Disable the

// functionality that depends on this permission.

if (CommonData.mChatService == null)

setupChat();

Toast.makeText(MyBlueToothClientActivity.this, "Permission denied for bluetooth", Toast.LENGTH_SHORT).show();

}

return;

}

// other 'case' lines to check for other

// permissions this app might request

}

}

虽然我能够得到的对话框请求启用蓝牙,我没有得到第二许可,即连接到设备。在logcat中,我得到:

01-01 06:41:24.334 25473-25473 E/BluetoothChat: ++ ON START ++

01-01 06:41:24.344 25473-25473 W/Activity: Can reqeust only one set of permissions at a time

而且由于我无法连接到设备,我只是在这里卡住了。而且这个代码在Android版本上运行良好,直到棒棒糖,只是导致棉花糖版本的问题。

2016-04-22

Mirhawk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值