Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.toDouble() locale and activity permission #1

Open
xenogenesi opened this issue Apr 18, 2021 · 1 comment
Open

.toDouble() locale and activity permission #1

xenogenesi opened this issue Apr 18, 2021 · 1 comment

Comments

@xenogenesi
Copy link

Thanks for sharing, I'm using a moto (9) play, it seems to be working but I had to apply two minor changes:

  • .toDouble() was failing with an exception invalid input 0,00, perhaps the locale I guess, so I used a different approach to trim the distance to two decimals.
  • ACTIVITY_RECOGNITION is needed since api level 29
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c6af43e..dedc7a0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
     package="com.daniyalak.stepcounterkotlin_androidfitnessapp">
 
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
 
     <application
         android:allowBackup="true"
diff --git a/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt b/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
index 25ed797..73aac13 100644
--- a/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
+++ b/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
@@ -59,7 +59,7 @@ class GeneralHelper {
         fun getDistanceCovered(steps: Int): String? {
             val feet = (steps * 2.5).toInt()
             val distance = feet/3.281
-            val finalDistance:Double = String.format("%.2f", distance).toDouble()
+            val finalDistance:Double = Math.round(distance * 100) / 100.0
             return "$finalDistance meter"
         }
     }
@daniyalahmedkhan
Copy link
Owner

Thanks for sharing, I'm using a moto (9) play, it seems to be working but I had to apply two minor changes:

  • .toDouble() was failing with an exception invalid input 0,00, perhaps the locale I guess, so I used a different approach to trim the distance to two decimals.
  • ACTIVITY_RECOGNITION is needed since api level 29
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c6af43e..dedc7a0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
     package="com.daniyalak.stepcounterkotlin_androidfitnessapp">
 
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
 
     <application
         android:allowBackup="true"
diff --git a/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt b/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
index 25ed797..73aac13 100644
--- a/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
+++ b/app/src/main/java/com/daniyalak/stepcounterkotlin_androidfitnessapp/helper/GeneralHelper.kt
@@ -59,7 +59,7 @@ class GeneralHelper {
         fun getDistanceCovered(steps: Int): String? {
             val feet = (steps * 2.5).toInt()
             val distance = feet/3.281
-            val finalDistance:Double = String.format("%.2f", distance).toDouble()
+            val finalDistance:Double = Math.round(distance * 100) / 100.0
             return "$finalDistance meter"
         }
     }

Yup, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants