当应用使用 Google Play 服务位置 API 获取用户的位置信息并且 GPS 被禁用时,会发生什么情况?编写什么代码来使应用要求用户打开 GPS?
此外,应该为Marshmallow或更高版本编写哪些代码来请求访问位置的权限(因为大于API 23的版本要求应用程序运行时的权限(。
如果用户不授予权限,如何处理?
当应用使用 Google Play 服务位置 API 来执行任务信息时会发生什么情况 获取用户的位置并且GPS被禁用?编写什么代码 让应用要求用户打开 GPS?
如果禁用GPS,则可以通过Google Play服务检索最后的已知位置,
-
创建
GoogleApiClient
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this( .addConnectionCallbacks(this( .addOnConnectionFailedListener(this( .addApi(LocationServices.API(.build((;
像这样获取最后一个已知位置,
LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
https://developer.android.com/training/location/retrieve-current.html
另外,应该为棉花糖或更高版本编写哪些代码 请求访问位置的权限(版本大于 API 23 请求应用程序运行时的权限(。
如果用户不授予权限,如何处理?
从Android Marshmallow中,有必要在运行时请求权限。这是它的链接,
https://developer.android.com/training/permissions/requesting.html