Android安全位置测试

时间:2016-09-29 15:23:24

标签: android location criteria

大家好我很好奇如何在下面的代码中解决位置安全问题:

 private void myLocaion(){
    Criteria criteria = new Criteria(); 
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    final String myBestProvider = locationManager.getBestProvider(criteria, false); 
    Toast.makeText(gtApplicationContext(), myBestProvider, Toast.LENTH_SHORT).show(); 

    myLocationListener = new LocationListener{ 

        public void onLocationChaned(Location location){
            Toas.makeText(getApplicationContext(),
                            location.getLatitude() + " " + 
                            location.getLongiude(), Toast.LENGTH_SHORT).show();
        }
        public void onStatusChanged(String provider, int status, Bundle extras){}
        public void onProviderEnabled(String provider){}
        public void onProviderDisabled(String provider){}
    };//LocationListener
    locationManager.requestLocationUpdates(MyBestProvider, 0, 0, myLocationListener)

}
似乎Android Studio声明的开发环境对此代码的安全性问题:

locationManager.requestLocationUpdates(MyBestProvider, 0, 0, myLocationListener)

Android API:23

1 个答案:

答案 0 :(得分:2)

Android API 23需要在操作代码

之前进行安全性审核

有3种方法可以解决这个问题:

1)尝试给开发环境修复安全代码要求

2)编译较旧的开发环境Android Studio

3)更改目标

的版本

以下是如何更改:

文件 - >项目结构.. - > Flavors-> Targer Sdk版 Change SDK Version 如果到目前为止一切正常,您可以提前编写申请并发送位置信息方法onLocationChanged( )来映射函数:

Uri.parse("geo:" + myLocation.getLatitude() + "," myLocation.getLongitude())

然后:

public void showMap( Uri geoLocation ){
    Intent intent = new Intent (Intent.ACTION_VIEW); 
    Intent.setData(geoLocation); 
    if (intent.resolveActivity(getPackageManager()) != null){
        startActivity(intent); 
        locationManager.removeUpdates(mylocationListener;)
    }
}