Java 位置服务第二次不工作
如果我运行这个,它将第一次询问位置权限并给出gps位置,但在再次关闭和打开它后,它不会给出任何数据 有卸载和重新安装它agian,然后它的作品很好,有人能帮我吗?? 我已经为此工作了几个星期,我被困在这里Java 位置服务第二次不工作,java,android,Java,Android,如果我运行这个,它将第一次询问位置权限并给出gps位置,但在再次关闭和打开它后,它不会给出任何数据 有卸载和重新安装它agian,然后它的作品很好,有人能帮我吗?? 我已经为此工作了几个星期,我被困在这里 locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationListener = new LocationListener() { @Override
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
new task().execute("http://192.168.0.104:1337/updatelocation?user_id="+tveid.getText()+"&lat="+location.getLatitude()+"&lng="+location.getLongitude());
Toast.makeText(TrackingGpsLocation.this,location.getLatitude() +" "+location.getLongitude(), Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.INTERNET
}, 10);
return;
}
}else {
configureButton();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case 10:
if (grantResults.length>0 && grantResults[0] == getPackageManager().PERMISSION_GRANTED)
configureButton();
return;
}
}
private void configureButton() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
locationManager.requestLocationUpdates("gps", 5000, 0, locationListener);
}
});
}
为什么不使用GoogleLocationServicesAPI,它提供了一个更强大、更高级的框架,可以自动化诸如位置提供商选择和电源管理之类的任务?不管怎样,您在onResume和onPause call removeUpdatesIs中请求çpcationUpdates所有这些都在onCreate中?是的,所有这些都在OnCreateTry中尝试此代码为什么不使用Google Location Services API,它提供了一个更强大、更高级的框架来自动化任务,如位置提供程序选择和电源管理?不管怎样,您在onResume和onPause call RemoveUpdates中请求çpcationUpdates所有这些都在onCreate中?是的所有都在OnCreateTry中尝试此代码