cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
550 stars 675 forks source link

[health 3.2.0] I can't fetch step data #429

Open EunyoungY opened 3 years ago

EunyoungY commented 3 years ago

How can I set step data? I ran the example code, but It doesn't give step data. However, I could get weight and height data.

I also tried 'flutter_activity_recognition' package to check and request activity recognition permission, and It still doesn't work

Raja1234p commented 3 years ago

I have implemented a pedometer but it os not showing result on debug and release APK kindly help

import 'package:flutter/material.dart'; import 'dart:async';

import 'package:pedometer/pedometer.dart';

String formatDate(DateTime d) { return d.toString().substring(0, 19); }

void main() { runApp(MyApp()); }

class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); }

class _MyAppState extends State { Stream _stepCountStream; Stream _pedestrianStatusStream; String _status = '?', _steps = '?';

@override void initState() { super.initState(); initPlatformState(); }

void onStepCount(StepCount event) { print(event); setState(() { _steps = event.steps.toString(); }); }

void onPedestrianStatusChanged(PedestrianStatus event) { print(event); setState(() { _status = event.status; }); }

void onPedestrianStatusError(error) { print('onPedestrianStatusError: $error'); setState(() { _status = 'Pedestrian Status not available'; }); print(_status); }

void onStepCountError(error) { print('onStepCountError: $error'); setState(() { _steps = 'Step Count not available'; }); }

void initPlatformState() { _pedestrianStatusStream = Pedometer.pedestrianStatusStream; _pedestrianStatusStream .listen(onPedestrianStatusChanged) .onError(onPedestrianStatusError);

_stepCountStream = Pedometer.stepCountStream;
_stepCountStream.listen(onStepCount).onError(onStepCountError);

if (!mounted) return;

}

@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Pedometer example app'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Steps taken:', style: TextStyle(fontSize: 30), ), Text( _steps, style: TextStyle(fontSize: 60), ), Divider( height: 100, thickness: 0, color: Colors.white, ), Text( 'Pedestrian status:', style: TextStyle(fontSize: 30), ), Icon( _status == 'walking' ? Icons.directions_walk : _status == 'stopped' ? Icons.accessibility_new : Icons.error, size: 100, ), Center( child: Text( _status, style: _status == 'walking' || _status == 'stopped' ? TextStyle(fontSize: 30) : TextStyle(fontSize: 20, color: Colors.red), ), ) ], ), ), ), ); } }

EmanueleVinci commented 3 years ago

By default you don't have the permission to access activity_recognition (Android). Did you put the permission request in the Android Manifest?

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

I don't know about 'flutter_activity_recognition' package, but with "permission_handler" it works. Try like this:

  static Future<bool> _checkPermission() async {
    final status = await Permission.activityRecognition.status;

    if (status != PermissionStatus.granted) {
      final result = await Permission.activityRecognition.request();
      if (result == PermissionStatus.granted) {
        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  }

Apparently in iOS you don't have to ask permission, but I'm not sure.

Raja1234p commented 3 years ago

I have done all these but still it is not working from my side . Thanks for your response.

Regards Raja Pooran kumar

On Thu, 4 Nov 2021, 18:34 Emanuele Vinci, @.***> wrote:

By default you don't have the permission to access activity_recognition (Android). Did you put the permission request in the Android Manifest?

I don't know about 'flutter_activity_recognition' package, but with "permission_handler" it works. Try like this:

static Future _checkPermission() async { final status = await Permission.activityRecognition.status;

if (status != PermissionStatus.granted) {
  final result = await Permission.activityRecognition.request();
  if (result == PermissionStatus.granted) {
    return true;
  } else {
    return false;
  }
} else {
  return true;
}

}

Apparently in iOS you don't have to ask permission, but I'm not sure.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cph-cachet/flutter-plugins/issues/429#issuecomment-960940120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKMIAP2W3OFCDB4BUFS6ZWDUKKDWNANCNFSM5F4UUHZA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.