Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that the Android10/AndroidQ phone can not be positioned properly in the background

Shulou Source: shulou.com Published: 2022-06-02 17:41:18 10月03日 Update

This article mainly introduces "how to solve the problem that the Android10/AndroidQ phone cannot be positioned properly in the background". In the daily operation, I believe many people have doubts about how to solve the problem that the Android10/AndroidQ phone cannot be positioned properly in the background. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt that "how to solve the problem of Android10/AndroidQ phone can not be positioned normally in the background". Next, please follow the editor to study!

Android 10 was officially released in September 2019, bringing about a very significant change in GPS permissions. Users are provided with permission only when using this application. Once users choose "allow only when using this application", APP will not be able to record GPS tracks properly in the background or when locking the screen, which has a great influence on DiDi, bike sharing and running software.

In response to this change, Google also gives a new solution.

Step 1: upgrade SDK

Modify build.gradle and upgrade compileSdkVersion and targetSdkVersion of APP.

Android {compileSdkVersion 29 defaultConfig {targetSdkVersion 29}}

Step 2: increase the permission of background location

Modify the AndroidManifest.xml file, add ACCESS_BACKGROUND_LOCATION permissions, and add android:foregroundServiceType= "location" to the corresponding service.

Step 3: apply for background location permission

If (Build.VERSION.SDK_INT > = Build.VERSION_CODES.Q) {ActivityCompat.requestPermissions (this,arrayOf (Manifest.permission.ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION))} else {ActivityCompat.requestPermissions (this,arrayOf (Manifest.permission.ACCESS_COARSE_LOCATION), 101)}

Through the above method, you can get whether the user allows APP background positioning, and if the user does not allow it, it will prompt the following dialog box.

At this point, the study on "how to solve the problem that Android10/AndroidQ phones can not be positioned properly in the background" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Background location problems mobile phones permissions users learning methods more upgrades help applications practical important next bikes dialogs files articles solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Shulou Tech Info MySQL Xiaomi