Android ACTIVITY_RECOGNITION Permission SDK 28 running on Android 10/Q (SDK 29)

后端 未结 3 1049
无人及你
无人及你 2021-02-06 05:30

My Android app targets SDK 28 and connects to Google Fit to upload data and read some other data. The app uses the HistoryAPI to read com.google.step_count.delta data.

T

3条回答
  •  隐瞒了意图╮
    2021-02-06 06:19

    Solved: In App Api Level 28 +

    
    

    The app should check if the permission is granted already:

    if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACTIVITY_RECOGNITION)
              != PackageManager.PERMISSION_GRANTED) {
          // Permission is not granted
    }
    

    To request the permission:

    ActivityCompat.requestPermissions(thisActivity,
                      arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
                      MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION);
    

    Learn more about requesting Android runtime permissions.

    If your app targets SDK level 28 or below, it must specify the com.google.android.gms.permission.ACTIVITY_RECOGNITION permission in its manifest file.

提交回复
热议问题