Я работаю над получением ударов в минуту с помощью API датчиков от Google. Я включил свое разрешение датчика местоположения и тела в manifest.xml и использую метод permissions.with onResume ().
protected void onResume() {
super.onResume();
// When permissions are revoked the app is restarted so onCreate is sufficient to check for
// permissions core to the Activity's functionality.
Permissions.with(this)
.request(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BODY_SENSORS)
.withPermanentDenialDialog("Fitness app requires these permissions")
.onAllGranted(this::findFitnessDataSources)
.onAnyDenied(this::finish)
.execute();
}
Это мой файл манифеста
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
Это исключение, которое я получаю
Process: com.example.fitnessapp, PID: 5231
java.lang.RuntimeException: Unable to resume activity {com.example.fitnessapp/com.example.fitnessapp.SensorClass}: java.lang.IllegalArgumentException: permission cannot be null or empty
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3536)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3576)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.IllegalArgumentException: permission cannot be null or empty
at android.content.pm.PackageManager.buildRequestPermissionsIntent(PackageManager.java:3465)
at android.app.Activity.requestPermissions(Activity.java:4293)
at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:502)
at com.example.fitnessapp.permissions.Permissions.requestPermissions(Permissions.java:198)
at com.example.fitnessapp.permissions.Permissions.access$300(Permissions.java:35)
at com.example.fitnessapp.permissions.Permissions$ActivityPermissionObject.requestPermissions(Permissions.java:306)
at com.example.fitnessapp.permissions.Permissions$PermissionsBuilder.executePermissionsRequest(Permissions.java:179)
at com.example.fitnessapp.permissions.Permissions$PermissionsBuilder.execute(Permissions.java:146)
at com.example.fitnessapp.SensorClass.onResume(SensorClass.java:127)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270)
at android.app.Activity.performResume(Activity.java:6971)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3513)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3576)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)