在我的Android应用程序中,我希望用户允许使用google playservices。有没有办法做到这一点?
与阅读联系人一样,我们使用:
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(getActivity(),
android.Manifest.permission.)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
android.Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(getActivity(),
new String[]{android.Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
P.S:我的gradle.build文件有:
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-location:8.1.0'
答案 0 :(得分:1)
Google Play服务是图书馆。您永远不需要请求使用它们的许可。 Bt取决于您想要使用的功能,您需要获得许可。
喜欢使用地图,您需要询问位置许可