我有访问 GPS 的应用程序...但是如果我的 GPS 未启用,我的应用程序将强制关闭...这是我的代码,
private void cekGPS() {
// TODO Auto-generated method stub
LocationManager locationManager;
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 1.0F, this);
boolean isGPS=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//pastike sek murup po rak GPS ,e
if(isGPS==false){
Toast.makeText(this, "GPS gak aktip", Toast.LENGTH_LONG);
System.out.println("GPSmati");
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
} else {
//lha nek wes pasti murup langsung di cek last know trus lebok2.e
System.out.println("GPSmurup");
Toast.makeText(this, "GPS Aktif", Toast.LENGTH_LONG).show();
}
}
但我有错误:
03-22 11:16:14.525: ERROR/AndroidRuntime(5426): Caused by: java.lang.IllegalArgumentException: provider==null
有谁能够帮我?谢谢你。