【发布时间】:2016-05-04 19:30:31
【问题描述】:
定义位置后,我得到红色下划线,上面写着:“调用需要权限,可能会被用户拒绝:代码应明确检查权限是否可用(使用'checkPermission')或处理潜在的'SecurityException '
我该如何解决这个问题?
public class map extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private FloatingActionButton plus;
LocationManager lm;
Location location;
double latitude, longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location==null){
//Location wasnt gathered
}else{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
plus = (FloatingActionButton) findViewById(R.id.newPlace);
plus.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(map.this, newPlacePop.class));
}
});
}
【问题讨论】:
标签: android permissions location