Android 23使用定位权限报错Call requires permission which may be rejected by user
来源:互联网 发布:opticalflares mac 编辑:程序博客网 时间:2024/06/01 09:31
报错了“Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission
) or explicitly handle a potential SecurityException
”
权限问题
使用时,需要检查用户是否授权
参考链接1:http://blog.5ibc.net/p/62176.html
参考链接2:http://blog.csdn.net/qq_27278679/article/details/51095770
代码解决(亲测可用):
private void getlocationGps(){//此处的判定是主要问题,API23之后需要先判断之后才能调用locationManager中的方法//包括这里的getLastKnewnLocation方法和requestLocationUpdates方法 if(ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED) { //获取定位服务 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //获取当前可用的位置控制器 List<String> list = locationManager.getProviders(true); if (list.contains(LocationManager.GPS_PROVIDER)) { //是否为GPS位置控制器 provider = LocationManager.GPS_PROVIDER; } else if (list.contains(LocationManager.NETWORK_PROVIDER)) { //是否为网络位置控制器 provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(this, "请检查网络或GPS是否打开", Toast.LENGTH_LONG).show(); return; } Location location = locationManager.getLastKnownLocation(provider); if (location != null) { //获取当前位置,这里只用到了经纬度 String string = "纬度为:" + location.getLatitude() + ",经度为:" + location.getLongitude(); }//绑定定位事件,监听位置是否改变//第一个参数为控制器类型第二个参数为监听位置变化的时间间隔(单位:毫秒)//第三个参数为位置变化的间隔(单位:米)第四个参数为位置监听器 locationManager.requestLocationUpdates(provider, 2000, 2, locationListener); }}public LocationListener locationListener=new LocationListener() { @Override public void onLocationChanged(Location location) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { }}; //关闭时解除监听器 @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); //api23需要这样写 if(ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED) { if (locationManager != null) { locationManager.removeUpdates(locationListener); } } }
0 0
- Android 23使用定位权限报错Call requires permission which may be rejected by user
- 使用GPS提示的问题是Call requires permission which may be rejected by user: code should explicitly check to s
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- call requires permission which may be rejected by user;code should explicitly check to see if permis
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- Tomcat报错,May be locked by another process.
- android.permission.INSTALL_PACKAGES 权限报错
- android.permission.WRITE_SECURE_SETTINGS权限报错
- Tomcat Publish报错(Could not delete ........ May be locked by another process.)
- Android 6.0 访问图库时,报错 requires android.permission.READ_EXTERNAL_STORAGE异常
- 编译报错“a pointer to a bound function may only be used to call the function”的解决办法
- Call requires API level 11 (current min is 8): android.app.Activity#onCreateView 报错问题
- Call requires API level 3 (current min is 2) android导入程序报错
- android 6.0以下系统 应用出现crash,报错:使用android.permission.READ_PHONE_STATE权限出现SecurityException异常
- android studio报错Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled解决方案
- Android Studio运行报错Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled
- Android Studio报错:Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled
- android编译报错 warning: Clock skew detected. Your build may be incomplete. 的解决方式
- Hibernate+Struts2 分页实现
- 【HTTP协议】请求、响应、状态码
- 开源项目【LikeCloudMusic 云音】仿网易云音乐
- Android 中SocketClient client = new SocketClient("IP_ADDRESS",8000)出错
- Android 图片在Editext里面,不是放在editext右边 是放在里面 右侧
- Android 23使用定位权限报错Call requires permission which may be rejected by user
- 爬有道在线翻译(已完善)
- JAVA学习推荐书籍
- 辞旧迎新,再见2016,欢迎2017
- 深入解读Spring Framework事务管理(第四弹:基于@Transactional注解的声明式事务管理)
- 【R语言】 之 基础知识初探
- cocos2d-x多触点问题
- 算法杂货铺——分类算法之贝叶斯网络(Bayesian networks)
- 求助~如何开始一个企业级应用。