在android 6.0上,你必須在運行時請求一些權限。這是在這裏解釋https://developer.android.com/training/permissions/requesting.html
在在Android 6.0(API級別23)開始,用戶權限授予 應用應用程序運行時,而不是當他們安裝應用程序。
在運行時,你應該這樣做(要使用GPS之前)要求的權限:
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Check Permissions Now
private static final int REQUEST_LOCATION = 2;
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Display UI and wait for user interaction
} else {
ActivityCompat.requestPermissions(
this, new String[]{Manifest.permission.LOCATION_FINE},
ACCESS_FINE_LOCATION);
}
} else {
// permission has been granted, continue as usual
Location myLocation =
LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
}
您有GPS這裏https://developers.google.com/android/guides/permissions
一個例子這是一個很好的演示HTTPS ://www.learn2crack.com/2015/10/android-marshmallow-permissions.html – andres83