If the bluetooth device is HID then it is triggering a "keyboard" configuration change event which restarts the activity, similar to orientation changes. Add a configChanges="keyboard|screenSize" to your AndroidManifest.xml. I also have keyboardHidden in there for slideout keyboards, along with orientation since I don't want to reload my page when the device is rotated.
My webview reloads when bluetooth disconnects or reconnects
-
10-07-2023 - |
Domanda
I have an app that has an issue with bluetooth devices. When i disconnect or reconnect a bluetooth device the app seems to reload or i would say reload webview. It doesn't crash the app because I'm catching the connects and disconnects using the a receiver. Here is the code I'm using and where I'm stuck at. The toast are working and i can't figure out why its refreshing the entire view.
public class MyBTReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.bluetooth.device.action.ACL_CONNECTED"))
{
Toast.makeText(context, "BT connect", Toast.LENGTH_SHORT).show();
}else if(intent.getAction().equals("android.bluetooth.device.action.ACL_DISCONNECTED"))
{
Toast.makeText(context, "BT disconnect", Toast.LENGTH_SHORT).show();
}
}
}
<receiver android:name=".MyBTReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow