Closed hilmiardani closed 7 months ago
Are you testing on Android 14?
Please try v2 and let me know about the outcome:
https://github.com/matinzd/react-native-health-connect/releases/tag/v2.0.0
I'm using Android 11. I'll try the v2 first
Here's the update.
When i upgrade to version 2.0.0 my app crash when i run the app. So i rollback to this version ^1.2.3 and my app works fine. I'm using Android 11
Please attach adb logs for the crash.
This is my adb log
This is the text
02-23 14:23:51.970 28217 28217 I com.healthapp: Late-enabling -Xcheck:jni 02-23 14:23:51.988 28217 28217 I com.healthapp: Unquickening 23 vdex files! 02-23 14:23:52.501 28217 28217 W linker : Warning: "/data/app/~~yjRYzwFhCr-Hl5GJbNNlHw==/com.healthapp-kbPnG9r3dFM9WBy3ZARPHg==/base.apk!/lib/arm64-v8a/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) 02-23 14:23:52.506 28217 28217 W linker : Warning: "/data/app/~~yjRYzwFhCr-Hl5GJbNNlHw==/com.healthapp-kbPnG9r3dFM9WBy3ZARPHg==/base.apk!/lib/arm64-v8a/libruntimeexecutor.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) 02-23 14:23:52.640 28217 28256 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 14:23:52.652 28217 28262 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 14:23:52.657 28217 28217 W com.healthapp: Accessing hidden field Landroid/view/View;->mKeyedTags:Landroid/util/SparseArray; (greylist, reflection, allowed) 02-23 14:23:52.657 28217 28217 W com.healthapp: Accessing hidden field Landroid/view/View;->mListenerInfo:Landroid/view/View$ListenerInfo; (greylist, reflection, allowed) 02-23 14:23:52.657 28217 28217 W com.healthapp: Accessing hidden field Landroid/view/View$ListenerInfo;->mOnClickListener:Landroid/view/View$OnClickListener; (greylist, reflection, allowed) 02-23 14:23:52.691 28217 28271 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 14:23:52.756 28217 28275 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 14:23:52.789 28217 28217 W com.healthapp: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 02-23 14:23:52.790 28217 28217 W com.healthapp: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 02-23 14:23:52.879 1563 1841 I ActivityTaskManager: Displayed com.healthapp/.MainActivity: +998ms 02-23 14:23:52.986 11477 11477 I GoogleInputMethodService: GoogleInputMethodService.onStartInput():1889 onStartInput(EditorInfo{EditorInfo{packageName=com.healthapp, inputType=0, inputTypeString=NULL, enableLearning=false, autoCorrection=false, autoComplete=false, imeOptions=0, privateImeOptions=null, actionName=UNSPECIFIED, actionLabel=null, initialSelStart=-1, initialSelEnd=-1, initialCapsMode=0, label=null, fieldId=-1, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false) 02-23 14:23:54.716 28217 28304 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 14:23:56.731 28217 28306 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 14:23:58.391 28217 28310 W com.healthapp: Accessing hidden field Ljava/lang/reflect/Field;->accessFlags:I (greylist, reflection, allowed) 02-23 14:23:58.668 28217 28319 D Linux : [Posix_connect Debug]Process com.healthapp :8097 02-23 14:23:58.748 28217 28320 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 14:23:59.001 28217 28309 W com.healthapp: CheckJNI: method to register "installJSIBindings" not in the given class. This is slow, consider changing your RegisterNatives calls. 02-23 14:23:59.129 28217 28323 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 14:23:59.688 28217 28217 W com.healthapp: Accessing hidden field Landroid/widget/ScrollView;->mScroller:Landroid/widget/OverScroller; (greylist, reflection, allowed) 02-23 14:23:59.853 28217 28326 E AndroidRuntime: Process: com.healthapp, PID: 28217
I am not seeing any exception or error log here. Try to filter your adb log level. Also try to filter it based on the package name of your app.
This is my new log and based on the package name of my app. my app name is HealthApp
02-23 15:19:13.609 14593 14593 I Finsky : [2] ajkr.c(76): VerifyApps: Install-time verification requested for package com.healthapp, id = 10 02-23 15:19:13.720 14593 9443 I Finsky : [4331] VerifyAppsInstallTask.aks(63): VerifyApps: Anti-malware verification task started for package=com.healthapp 02-23 15:19:16.972 14593 9448 I Finsky : [4335] ajqg.f(71): VerifyApps: Verification package=com.healthapp, id=10, response=0, upload_requested=false 02-23 15:19:16.998 14593 9443 I Finsky : [4331] VerifyRequiredSplitTypesInstallTask.aks(41): VerifyApps: Starting required split types check for com.healthapp. 02-23 15:19:17.064 14593 9443 I Finsky : [4331] VerifyRequiredSplitTypesInstallTask.aks(712): VerifyApps: Required split types check successful for com.healthapp. 02-23 15:19:17.096 14593 9443 I Finsky : [4331] VerifyV31SignatureInstallTask.e(150): VerifyApps V31SignatureVerification: Successful verification for the package: com.healthapp using APK Signature Scheme v3 02-23 15:19:17.128 14593 14593 I Finsky : [2] VerifyInstallTask.akr(79): VerifyApps: Verification complete: id=10, package_name=com.healthapp 02-23 15:19:17.751 5098 5098 I GsaVoiceInteractionSrv: O received Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.healthapp flg=0x4000010 (has extras) } 02-23 15:19:17.817 5098 5098 I GsaVoiceInteractionSrv: O received Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.healthapp flg=0x4000010 (has extras) } 02-23 15:19:17.875 5098 5098 I GsaVoiceInteractionSrv: O received Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:com.healthapp flg=0x4000010 (has extras) } 02-23 15:19:17.976 14593 14593 I Finsky : [2] kjd.f(9): AIM: AppInfoCacheUpdater -> invalidating apps: [com.healthapp] 02-23 15:19:18.224 14593 14639 I Finsky : [4143] kkv.a(55): AIM: AppInfoManager-Perf > OnDeviceAppInfo > cacheHitCount=0, cacheMissCount=1. Missed in cache (limit 10) : [com.healthapp] 02-23 15:19:18.327 14593 14593 I Finsky : [2] sab.ahM(67): IQ: onPackageRemoved com.healthapp, replacing=true, uninstallingFromPlay=false 02-23 15:19:18.387 14593 14593 I Finsky : [2] kjd.f(9): AIM: AppInfoCacheUpdater -> invalidating apps: [com.healthapp] 02-23 15:19:18.390 14593 14641 I Finsky : [4145] kkv.a(55): AIM: AppInfoManager-Perf > OnDeviceAppInfo > cacheHitCount=0, cacheMissCount=1. Missed in cache (limit 10) : [com.healthapp] 02-23 15:19:19.194 5474 9481 W SQLiteLog: (28) double-quoted string literal: "com.healthapp" 02-23 15:19:19.415 9632 9632 I com.healthapp: Late-enabling -Xcheck:jni 02-23 15:19:19.454 9632 9632 I com.healthapp: Unquickening 23 vdex files! 02-23 15:19:20.263 9632 9632 W com.healthapp: type=1400 audit(0.0:126066): avc: denied { search } for name="bbkcore" dev="mmcblk0p61" ino=20187 scontext=u:r:untrusted_app:s0:c28,c260,c512,c768 tcontext=u:object_r:vivo_data_file:s0 tclass=dir permissive=0 app=com.healthapp 02-23 15:19:20.773 9632 9632 W linker : Warning: "/data/app/~~xnSHLY4jPQFZdksVCQDOsw==/com.healthapp-twjO2KM6mfz3pX-TVnvvvQ==/base.apk!/lib/arm64-v8a/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) 02-23 15:19:20.779 9632 9632 W linker : Warning: "/data/app/~~xnSHLY4jPQFZdksVCQDOsw==/com.healthapp-twjO2KM6mfz3pX-TVnvvvQ==/base.apk!/lib/arm64-v8a/libruntimeexecutor.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) 02-23 15:19:21.048 9632 9775 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 15:19:21.048 9632 9776 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 15:19:21.064 9632 9632 W com.healthapp: Accessing hidden field Landroid/view/View;->mKeyedTags:Landroid/util/SparseArray; (greylist, reflection, allowed) 02-23 15:19:21.064 9632 9632 W com.healthapp: Accessing hidden field Landroid/view/View;->mListenerInfo:Landroid/view/View$ListenerInfo; (greylist, reflection, allowed) 02-23 15:19:21.070 9632 9632 W com.healthapp: Accessing hidden field Landroid/view/View$ListenerInfo;->mOnClickListener:Landroid/view/View$OnClickListener; (greylist, reflection, allowed) 02-23 15:19:21.125 9632 9787 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:21.163 9632 9632 W com.healthapp: type=1400 audit(0.0:126077): avc: denied { search } for name="bbkcore" dev="mmcblk0p61" ino=20187 scontext=u:r:untrusted_app:s0:c28,c260,c512,c768 tcontext=u:object_r:vivo_data_file:s0 tclass=dir permissive=0 app=com.healthapp 02-23 15:19:21.173 9632 9632 W com.healthapp: type=1400 audit(0.0:126078): avc: denied { search } for name="bbkcore" dev="mmcblk0p61" ino=20187 scontext=u:r:untrusted_app:s0:c28,c260,c512,c768 tcontext=u:object_r:vivo_data_file:s0 tclass=dir permissive=0 app=com.healthapp 02-23 15:19:21.212 9632 9793 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 15:19:21.233 9632 9632 W com.healthapp: type=1400 audit(0.0:126079): avc: denied { search } for name="bbkcore" dev="mmcblk0p61" ino=20187 scontext=u:r:untrusted_app:s0:c28,c260,c512,c768 tcontext=u:object_r:vivo_data_file:s0 tclass=dir permissive=0 app=com.healthapp 02-23 15:19:21.315 9632 9632 W com.healthapp: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 02-23 15:19:21.315 9632 9632 W com.healthapp: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 02-23 15:19:21.710 11477 11477 I GoogleInputMethodService: GoogleInputMethodService.onStartInput():1889 onStartInput(EditorInfo{EditorInfo{packageName=com.healthapp, inputType=0, inputTypeString=NULL, enableLearning=false, autoCorrection=false, autoComplete=false, imeOptions=0, privateImeOptions=null, actionName=UNSPECIFIED, actionLabel=null, initialSelStart=-1, initialSelEnd=-1, initialCapsMode=0, label=null, fieldId=-1, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false) 02-23 15:19:23.130 1563 1841 I ActivityTaskManager: Displayed com.healthapp/.MainActivity: +2s906ms 02-23 15:19:23.156 9632 9844 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:25.178 9632 9857 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:27.227 9632 9863 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:27.409 8390 8492 I DeviceAppInfoWork: remove existing package for update: com.healthapp 02-23 15:19:27.432 8390 8492 I DeviceAppInfoWork: remove existing package for update: com.healthapp 02-23 15:19:27.522 8390 8472 I DeviceAppInfoWork: remove existing package for update: com.healthapp 02-23 15:19:27.690 8390 8472 I DeviceAppInfoWork: remove existing package for update: com.healthapp 02-23 15:19:27.840 8390 8481 I DeviceAppInfoWork: remove existing package for update: com.healthapp 02-23 15:19:29.275 9632 9877 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:31.299 9632 9886 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:33.329 9632 9888 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:35.353 9632 9895 D Linux : [Posix_connect Debug]Process com.healthapp :9089 02-23 15:19:35.876 9632 9899 W com.healthapp: Accessing hidden field Ljava/lang/reflect/Field;->accessFlags:I (greylist, reflection, allowed) 02-23 15:19:36.490 9632 9909 D Linux : [Posix_connect Debug]Process com.healthapp :8097 02-23 15:19:36.498 9632 9898 W com.healthapp: CheckJNI: method to register "installJSIBindings" not in the given class. This is slow, consider changing your RegisterNatives calls. 02-23 15:19:36.605 9632 9911 D Linux : [Posix_connect Debug]Process com.healthapp :8081 02-23 15:19:37.210 9632 9632 W com.healthapp: Accessing hidden field Landroid/widget/ScrollView;->mScroller:Landroid/widget/OverScroller; (greylist, reflection, allowed) 02-23 15:19:37.353 9632 9913 E AndroidRuntime: Process: com.healthapp, PID: 9632 02-23 15:19:37.372 9632 9925 D Linux : [Posix_connect Debug]Process com.healthapp :9089
And this is the message when crash.
Sorry. I want to ask, should i add this? in MainActivity.kt?
package com.healthconnectexample
class MainActivity : ReactActivity() { /**
}
/**
Yes, it works when i add that code. But still there is no grant permission for active calories burned, and i've checked on the health connect application has been enable.
@matinzd using the v2, the app crash has fixed but still there is an issue with permissions, as you can see the exception its throwing while using the requestPermission method.
Even though there are permissions in the AndroidManifest file, still there is an issue while reading permissions. Is the setup instructions docs ... upto Date ?
If you see an error message, it means you have to specify a permission in your AndroidManifest file. If you've already done that and it's still not working, please share a small example of your code with the issue. This will help us better understand and fix the problem.
@abdullatifHH
You'll need to define this permission in your manifest, not android.permission.health.READ_ACTIVE_CALORIES_BURNED
:
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
This is in my AndroidManifest.xml
This is my function to call permission and get data
const readSampleData = async () => {
// initialize the client
const isInitialized = await initialize();
if (!isInitialized) {
return;
}
// request permissions
const grantedPermissions = await requestPermission([
{ accessType: 'read', recordType: 'Steps' },
{ accessType: 'read', recordType: 'Distance' },
{ accessType: 'read', recordType: 'FloorsClimbed' },
{ accessType: 'read', recordType: 'HeartRate' },
{ accessType: 'read', recordType: 'SleepSession' },
]);
console.log('Granted permissions: ', grantedPermissions);
const timeRangeFilter: TimeRangeFilter = {
operator: 'between',
startTime: new Date(date.setHours(0, 0, 0, 0)).toISOString(),
endTime: new Date(date.setHours(23, 59, 59, 999)).toISOString(),
};
// const currentDate = new Date();
const previousDay = new Date(date);
previousDay.setDate(date.getDate() - 1);
const timeRangeFilterPreviousDay: TimeRangeFilter = {
operator: 'between',
startTime: new Date(previousDay.setHours(0, 0, 0, 0)).toISOString(),
endTime: new Date(previousDay.setHours(23, 59, 59, 999)).toISOString(),
};
// Steps
const steps = await readRecords('Steps', { timeRangeFilter });
const totalSteps = steps.reduce((sum, cur) => sum + cur.count, 0);
setSteps(totalSteps);
// Distance
const distance = await readRecords('Distance', { timeRangeFilter });
const totalDistance = distance.reduce(
(sum, cur) => sum + cur.distance.inMeters,
0
);
console.log('Total Distance: ', totalDistance);
setDistance(totalDistance);
// Floors climbed
const floorsClimbed = await readRecords('FloorsClimbed', {
timeRangeFilter,
});
const totalFloors = floorsClimbed.reduce((sum, cur) => sum + cur.floors, 0);
setFlights(totalFloors);
// Heart rate
const heartRate = await readRecords('HeartRate', { timeRangeFilter });
// const totalHeartRate = heartRate
// console.log('Total Heart Rate: ', totalHeartRate);
// Sleep
const sleep = await readRecords('SleepSession', { timeRangeFilter: timeRangeFilterPreviousDay });
// const totalSleep = sleep
setSleepSession(sleep[0].stages || []);
setStartSleep(sleep[0].startTime);
setEndSleep(sleep[0].endTime);
// console.log('Sleep: ', sleep);
// Calories Burned
const result = await readRecords('ActiveCaloriesBurned', { timeRangeFilter });
// console.log('Result: ', result);
// Testing
readRecords('SleepSession', { timeRangeFilter: timeRangeFilterPreviousDay }).then((result) => {
// console.log('Retrieved records: ', JSON.stringify({ result }, null, 2)); // Retrieved records: {"result":[{"startTime":"2023-01-09T12:00:00.405Z","endTime":"2023-01-09T23:53:15.405Z","energy":{"inCalories":15000000,"inJoules":62760000.00989097,"inKilojoules":62760.00000989097,"inKilocalories":15000},"metadata":{"id":"239a8cfd-990d-42fc-bffc-c494b829e8e1","lastModifiedTime":"2023-01-17T21:06:23.335Z","clientRecordId":null,"dataOrigin":"com.healthconnectexample","clientRecordVersion":0,"device":0}}]}
});
};
But the granted permission didnt show granted permission for calory burned, i've allow all the permissions.
@matinzd thank you for your reply, following migration link has helped me. @hilmiardani FYI: please follow instructions in this link (https://developer.android.com/health-and-fitness/guides/health-connect/migrate/migrate-from-android-13-to-14)
@hilmiardani
// request permissions const grantedPermissions = await requestPermission([ { accessType: 'read', recordType: 'Steps' }, { accessType: 'read', recordType: 'Distance' }, { accessType: 'read', recordType: 'FloorsClimbed' }, { accessType: 'read', recordType: 'HeartRate' }, { accessType: 'read', recordType: 'SleepSession' }, ]);
I think you need to add ActiveCaloriesBurned here.
You are not passing ActiveCaloriesBurned
to requestPermission
function.
I will mark this as resolved.
@matinzd
I'm encountering the same issue.
I'm using Bare react native setup
I have placed the ActiveCaloriesBurned in the requestPermission
And also placed the permission in the AndroidManifest.xml file of my my app
This is under the main folder
this is under the debug folder
I got empty array on the requestPermission result
Describe the bug When requesting permissions on the first launch of my app it didn't show permission for calories. And when i check on the health connect app the permission didn't enable, and i try to enable it manually but when i open my app and log the result, the result is still an empty array
To Reproduce Steps to reproduce the behavior:
Expected behavior Show the permission for calory and the result
Screenshots
Environment: