我正在开发基于蓝牙的应用程序。Android 5.0中的蓝牙连接问题(棒棒糖)
有一个用户想要通过蓝牙将数据分享给其他用户的手机。 我正面临一个问题。
设备与其他设备配对。但如果配对的设备有Android 5.0(Lollipop)及以上版本的Android OS,那么我面临问题,问题是当屏幕关闭时,连接将会丢失。在Android 5.0下,它正常工作。 “短棍棒棒糖”那么为什么会发生这种情况呢?
这是我的代码。
private BluetoothAdapter mAdapter;
mAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mAdapter.isEnabled()) {
@SuppressWarnings("static-access")
Intent enableBTIntent = new Intent(mAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBTIntent);
}
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver1, filter);
find = new ArrayList<String>();
mAdapter.startDiscovery();
final BroadcastReceiver mReceiver1 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
pdialog = ProgressDialog.show(FindPeopleActivity.this,
"Please wait", "Device Scanning...");
// discovery starts, we can show progress dialog or perform
// other tasks
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED
.equals(action)) {
if (pdialog != null && pdialog.isShowing())
pdialog.dismiss();
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// bluetooth device found
BluetoothDevice device = (BluetoothDevice) intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
find.add(device.getAddress());
}
}
};
清单文件
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
如果有任何解决方案,链接,任何差别接近那里将是巨大的,并帮助不少。提前致谢。
是否有可能在数据传输是当时配对的设备必须解锁。 (仅适用于Lolipop设备)您可以为屏幕锁定lolipop设备做一些硬编码吗? – Vrajesh