This commit is contained in:
LLan 2025-01-08 18:06:23 +01:00
parent 42784d94eb
commit c47d5a4113
3 changed files with 12 additions and 16 deletions

View File

@ -104,7 +104,6 @@
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.WRITE_STEPS"/>
<uses-sdk tools:overrideLibrary="androidx.health.connect.client"/>
<!-- <uses-sdk tools:overrideLibrary="androidx.health.connect.client" /> &lt;!&ndash; Override the library's minSdkVersion &ndash;&gt;-->
<uses-feature
android:name="android.hardware.bluetooth"

View File

@ -346,7 +346,7 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
if ((boolean) exportHealthConnectEnabled) {
if(!grantedPermissions.containsAll(healthConnectUtils.requiredHealthConnectPermissions)) {
// If we weren't enabled at some point already, show Permission screen
healthConnectUtils.healthConnectLauncherInit().launch(healthConnectUtils.requiredHealthConnectPermissions);
healthConnectUtils.activityResultLauncher.launch(healthConnectUtils.requiredHealthConnectPermissions);
}
}
return true;

View File

@ -52,22 +52,26 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
public class HealthConnectUtils {
private static final Logger LOG = LoggerFactory.getLogger(HealthConnectUtils.class);
private final PreferenceFragmentCompat preferenceFragmentCompat;
Class<StepsRecord> stepsRecordJavaClass = StepsRecord.class;
Class<HeartRateRecord> heartrateRecordJavaClass = HeartRateRecord.class;
KClass<StepsRecord> stepsRecordKClass = JvmClassMappingKt.getKotlinClass(stepsRecordJavaClass);
KClass<HeartRateRecord> heartrateRecordKClass = JvmClassMappingKt.getKotlinClass(heartrateRecordJavaClass);
public Set<String> requiredHealthConnectPermissions = Set.of(
public final ActivityResultLauncher<Set<String>> activityResultLauncher;
private final Class<StepsRecord> stepsRecordJavaClass = StepsRecord.class;
private final Class<HeartRateRecord> heartrateRecordJavaClass = HeartRateRecord.class;
private final KClass<StepsRecord> stepsRecordKClass = JvmClassMappingKt.getKotlinClass(stepsRecordJavaClass);
private final KClass<HeartRateRecord> heartrateRecordKClass = JvmClassMappingKt.getKotlinClass(heartrateRecordJavaClass);
public final Set<String> requiredHealthConnectPermissions = Set.of(
HealthPermission.getReadPermission(stepsRecordKClass),
HealthPermission.getWritePermission(stepsRecordKClass),
HealthPermission.getReadPermission(heartrateRecordKClass),
HealthPermission.getWritePermission(heartrateRecordKClass)
);
public ActivityResultContract<Set<String>, Set<String>> requestPermissionResultContract = PermissionController.createRequestPermissionResultContract();
public HealthConnectUtils(PreferenceFragmentCompat fragmentCompat) {
preferenceFragmentCompat = fragmentCompat;
activityResultLauncher = preferenceFragmentCompat.registerForActivityResult(
requestPermissionResultContract,
this::permissionCallback
);
}
@SuppressLint("RestrictedApi")
@ -89,13 +93,6 @@ public class HealthConnectUtils {
}
}
public ActivityResultLauncher<Set<String>> healthConnectLauncherInit() {
return preferenceFragmentCompat.registerForActivityResult(
requestPermissionResultContract,
this::permissionCallback
);
}
public HealthConnectClient healthConnectInit(Context context) {
// First check if we can even use Health Connect
int availabilityStatus = HealthConnectClient.getSdkStatus(context);