resolve getParcelableExtra issue
This commit is contained in:
parent
6ab3760dce
commit
0a2c5fec87
5 changed files with 18 additions and 6 deletions
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import dagger.android.DaggerBroadcastReceiver
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
import info.nightscout.androidaps.events.EventBTChange
|
import info.nightscout.androidaps.events.EventBTChange
|
||||||
|
import info.nightscout.androidaps.extensions.safeGetParcelableExtra
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class BTReceiver : DaggerBroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
val device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java) ?: return
|
val device = intent.safeGetParcelableExtra(BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java) ?: return
|
||||||
|
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
BluetoothDevice.ACTION_ACL_CONNECTED ->
|
BluetoothDevice.ACTION_ACL_CONNECTED ->
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package info.nightscout.androidaps.extensions
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
|
||||||
|
fun <T> Intent.safeGetParcelableExtra(name: String?, clazz: Class<T>): T? =
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getParcelableExtra(name, clazz)
|
||||||
|
else @Suppress("DEPRECATION") getParcelableExtra(name)
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import info.nightscout.androidaps.extensions.safeGetParcelableExtra
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity
|
import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity
|
||||||
|
|
||||||
class PrefsFileContract : ActivityResultContract<Void?, PrefsFile?>() {
|
class PrefsFileContract : ActivityResultContract<Void?, PrefsFile?>() {
|
||||||
|
@ -15,7 +16,7 @@ class PrefsFileContract : ActivityResultContract<Void?, PrefsFile?>() {
|
||||||
|
|
||||||
override fun parseResult(resultCode: Int, intent: Intent?): PrefsFile? {
|
override fun parseResult(resultCode: Int, intent: Intent?): PrefsFile? {
|
||||||
return when (resultCode) {
|
return when (resultCode) {
|
||||||
FragmentActivity.RESULT_OK -> intent?.getParcelableExtra(OUTPUT_PARAM, PrefsFile::class.java)
|
FragmentActivity.RESULT_OK -> intent?.safeGetParcelableExtra(OUTPUT_PARAM, PrefsFile::class.java)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
|
import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
|
import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
||||||
|
import info.nightscout.androidaps.extensions.IntentExtensionKt;
|
||||||
|
|
||||||
public class InsightPairingActivity extends NoSplashAppCompatActivity implements InsightConnectionService.StateCallback, View.OnClickListener, InsightConnectionService.ExceptionCallback {
|
public class InsightPairingActivity extends NoSplashAppCompatActivity implements InsightConnectionService.StateCallback, View.OnClickListener, InsightConnectionService.ExceptionCallback {
|
||||||
|
|
||||||
|
@ -234,7 +235,8 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements
|
||||||
if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
|
if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
|
||||||
((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().startDiscovery();
|
((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().startDiscovery();
|
||||||
else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
|
else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
|
||||||
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice bluetoothDevice =
|
||||||
|
IntentExtensionKt.safeGetParcelableExtra(intent, BluetoothDevice.EXTRA_DEVICE, BluetoothDevice.class);
|
||||||
deviceAdapter.addDevice(bluetoothDevice);
|
deviceAdapter.addDevice(bluetoothDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import dagger.android.DaggerBroadcastReceiver
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
|
import info.nightscout.androidaps.extensions.safeGetParcelableExtra
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.pump.common.events.EventPumpConnectionParametersChanged
|
import info.nightscout.androidaps.plugins.pump.common.events.EventPumpConnectionParametersChanged
|
||||||
|
@ -17,8 +18,8 @@ import javax.inject.Inject
|
||||||
class BondStateReceiver(
|
class BondStateReceiver(
|
||||||
@StringRes var deviceAddress: Int,
|
@StringRes var deviceAddress: Int,
|
||||||
@StringRes var bondedFlag: Int,
|
@StringRes var bondedFlag: Int,
|
||||||
var targetDevice: String,
|
private var targetDevice: String,
|
||||||
var targetState: Int
|
private var targetState: Int
|
||||||
) : DaggerBroadcastReceiver() {
|
) : DaggerBroadcastReceiver() {
|
||||||
|
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
|
@ -33,7 +34,7 @@ class BondStateReceiver(
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
val action = intent.action
|
val action = intent.action
|
||||||
val device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java)
|
val device = intent.safeGetParcelableExtra(BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java)
|
||||||
aapsLogger.info(LTag.PUMPBTCOMM, "in onReceive: INTENT" + gson.toJson(intent))
|
aapsLogger.info(LTag.PUMPBTCOMM, "in onReceive: INTENT" + gson.toJson(intent))
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "onReceive. Device is null. Exiting.")
|
aapsLogger.error(LTag.PUMPBTCOMM, "onReceive. Device is null. Exiting.")
|
||||||
|
|
Loading…
Reference in a new issue