Reputation: 666
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.
Upvotes: 1
Views: 1040
Reputation: 1322
I have different approch to handle this issue.
Device will be wake up till data,file etc does not transfer. when finished then release this lock in activity onDestroy().
So this is just for android 5.0 or above. You have to first track sdk then find API Level 21 and ablove then implement this apporch.
see this: Screen Lock and unlock
Upvotes: 0
Reputation: 5720
Staring with Android 6.0 it is not enough to include permissions on manifest. You have to ask the user explicitly about each permission that is considered "dangerous".BluetoothDevice. ACTION_FOUND
requires BLUETOOTH and ACCESS_COARSE_LOCATION permissions
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
if this doesn't work then post your error log.
Upvotes: 2