如何按蓝牙启用对话框按“拒绝”按钮.我厌倦了使用“OnDismissListener”和“OnCancelListener”甚至试过“onActivityResult”但是没有用.代码是……
private BluetoothAdapter mBluetoothAdapter;
private static final int REQUEST_ENABLE_BT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isBleSupportedOnDevice()) {
initializeBtComponent();
} else {
finish();
}
}
private boolean isBleSupportedOnDevice() {
if (!getPackageManager().hasSystemFeature(
PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this,"BLE is not supported in this device.",Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
private void initializeBtComponent() {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
}
@Override
protected void onResume() {
super.onResume();
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,REQUEST_ENABLE_BT);
}
}
此代码提示用户使用对话框,直到他按下“允许”或“确定”按钮,但是一旦按下“拒绝”或“取消”按钮,我必须返回上一个活动.我怎么做,当我按下“拒绝”按钮时,是否有任何功能被调用.