安卓使用地图开发获取权限
1
private void getPermission() {
2
List<String> permissionList = new ArrayList<>();
3
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
4
permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
5
}
6
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
7
permissionList.add(Manifest.permission.READ_PHONE_STATE);
8
}
9
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
10
permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
11
}
12
if (!permissionList.isEmpty()) {
13
String[] permissions = permissionList.toArray(new String[permissionList.size()]);
14
ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
15
}
16
}
Manifest中权限申请
1
<!-- 用于进行网络定位 -->
2
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3
<!-- 用于访问GPS定位 -->
4
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
5
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
6
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
8
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
9
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位 -->
10
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
11
<!-- 用于访问网络,网络定位需要上网 -->
12
<uses-permission android:name="android.permission.INTERNET" />
13
<!-- 用于读取手机当前的状态 -->
14
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
15
<!-- 写入扩展存储,向扩展卡写入数据,用于写入缓存定位数据 -->
16
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
17
<!-- 用于申请调用A-GPS模块 -->
18
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
19
<!-- 用于申请获取蓝牙信息进行室内定位 -->
20
<uses-permission android:name="android.permission.BLUETOOTH" />
21
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
22
<uses-permission android:name="android.permission.INTERNET" />