Closed BenLaKnet closed 2 months ago
It's either a separate app or as part of the settings
I found [com.lampa.startapp](https://github.com/lampaa/com.lampa.startapp)
ahh I didn't get the question, you mean how do I programmatically open the HealthConnect settings?
I have no idea, as said, it's either buried in the settings or is installed as a separate app. You will need to send an Intent, but I don't know which one exactly. If you find out, let me know and I can try to add this functionality to the plugin.
I suspect it has something to do with this: https://developer.android.com/reference/android/health/connect/HealthConnectManager#ACTION_MANAGE_HEALTH_PERMISSIONS
the issue is that this is supported from API 34 and on, so for earlier versions I would need to find out how this is done through the external app.
Hi,
I tried this plugin and it is running:
function openHealthSettings() {
if (cordova.platformId == "android") {
var pkgName = "com.google.android.apps.healthdata"
var sApp = startApp.set({
"package": pkgName,
"application": pkgName
});
sApp.check(
function (values) {
//console.log(JSON.stringify(values));
if (values.versionName) {
sApp.start();
}
else {
cordova.InAppBrowser.open('https://play.google.com/store/apps/details?id=' + pkgName, '_system', 'location=yes');
}
},
function (error) {
console.log(error);
}
);
}
else if (cordova.platformId == "ios") {
var sApp = startApp.set("x-apple-health://").start();
}
}
so that starts an Android Intent with "com.google.android.apps.healthdata". Have you tried it on Android 14 ? I was wondering if this is the same on all versions of the OS
No I just have Android 10 and 13.
After updating on Android 13, it does not work. I will try to see what happens.
It triggers an error when Health Connect is not installed. It is running now.
What could you do to use Intent with your plugin and open settings or install health ?
launching an Intent in Android is trivial, but you need to identify which intent to launch (is it com.google.android.apps.healthdata ?). If you have time, mabe you can try adding a function that does that?
fun openHealthConnect() { if(healthConnectHandler.isInstalled()) { val intent = Intent(HealthConnectClient.ACTION_HEALTH_CONNECT_SETTINGS) bridge.activity.startActivity(intent) } else { val providerPackageName = "com.google.android.apps.healthdata"; val uriString = "market://details?id=$providerPackageName&url=healthconnect%3A%2F%2Fonboarding" bridge.activity.startActivity( Intent(Intent.ACTION_VIEW).apply { setPackage("com.android.vending") data = Uri.parse(uriString) } ) }
it works in all versions.
that version compatibilit android itself takes care does this help?
yes it does! Weirdly, I have it as HealthConnectClient.ACTION_HEALTH_CONNECT_SETTINGS_LEGACY, but it's using androidx. The string corresponds to: "androidx.health.ACTION_HEALTH_CONNECT_SETTINGS". I can add it to the plugin, but I'd need to check if it works on Android 14 too, because there HealthConnect becomes embedded into the OS and is treated slightly differently. In fact, HealthConnectManager.ACTION_MANAGE_HEALTH_PERMISSIONS (which is NOT within androidx, but available from Android 14) corresponds to the string "android.health.connect.action.MANAGE_HEALTH_PERMISSIONS" , which is different.
the API has this function which fits 100% with what we need: https://developer.android.com/reference/androidx/health/connect/client/HealthConnectClient#getHealthConnectManageDataIntent(android.content.Context,kotlin.String)
Unfortunately it's not available in AndroidX yet, so I cannot call it at the moment. When we will able to use android 14 as minimum API level, then we will be able to use this API to its full extent.
When you will publish the new version?
Help me, please, I am waiting the new version to publish updates on my app. Many thanks.
Hi, I am a bit overworked these days, can you maybe test the latest code and confirm that it works on both Android and iOS? Particularly, I would need to check that the openHealthSettings() function works on both. If you tell me it's working for you I can publish it.
OK many thanks for your answer.
I have to see that.
I have tested it and released it, v 3.2.0
OK, it is running for me.
Thank you very much for your job @dariosalvi78
Hi,
I do not know how is it possible to open health connect to see authorization of my app and change options of read/write.
Many thanks.