Open EunyoungY opened 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
@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:
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.
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.
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