I am developing Bluetooth based app.
There is one user who wants to share data to other user’s phone through Bluetooth . I am facing one issue.
Device is paired with other device. But if paired device has Android 5.0 (Lollipop) and above version of android OS then I face problem, The problem is when screen is off that time connection will be lost. Below Android 5.0 it work s properly. “In short problem face in Lollipop” So why this is happen ?
Here is my code.
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());
}
}
};
In Manifest file
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
If there is any solution, link, any difference approach there would be great and helps lot. Thanks in advance.