AndroidQ新增定位權限:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
定位服務的判斷和開啟:
/**
* ==============================================
* author : carl
* e-mail : [email protected]
* time : 2020/05/29
* desc : 權限管理類
* version: 1.0
* ==============================================
*/
public class PermissionUtils {
/**
* 檢查定位服務的開啟狀态,并跳轉申請
*/
public static void openLocationService() {
//APP 替換成自己的Application
LocationManager manager = (LocationManager) App.getInstance().getSystemService(LOCATION_SERVICE);
boolean isGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetwork = manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPS && !isNetwork) {
T.show("請開啟定位服務!");
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
App.getInstance().startActivity(intent);
}
}
}