Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting force close application if GPS disabled
    primarykey
    data
    text
    <p>I have application to get location from gps<br> but if GPS disabled my application getting force close<br> in emulator it's fine not error,but if run in device it's force close<br> how can i do this?? this is my code:</p> <pre><code>public class Track extends Activity implements LocationListener{ String curTime; double lat; double lng; double alt; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final LocationManager locationManager; String context = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(context); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); final String provider = locationManager.getBestProvider(criteria, true); Dbhelper helper = new Dbhelper(this); final SQLiteDatabase db = helper.getWritableDatabase(); updateWithNewLocation(null); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask(){ @Override public void run(){ db.isOpen(); db.execSQL("INSERT INTO location (longitude,latitude,altitude,tgl_buat) VALUES " + "('"+lng+"','"+lat+"','"+alt+"','"+curTime+"')"); //db.close(); } }, 10*60*1000, 10*60*1000); locationManager.requestLocationUpdates(provider, (10*60*1000), 10, locationListener); PackageManager manager = this.getPackageManager(); PackageInfo info = null; try { info = manager.getPackageInfo(this.getPackageName(), 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast.makeText(this, "PackageName = " + info.packageName + "\nVersionCode = " + info.versionCode + "\nVersionName = " + info.versionName + "\nPermissions = "+info.permissions, Toast.LENGTH_SHORT).show(); System.out.println("PackageName = " + info.packageName + "\nVersionCode = " + info.versionCode + "\nVersionName = " + info.versionName + "\nPermissions = "+info.permissions); } private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location); } public void onProviderDisabled(String provider){ updateWithNewLocation(null); } public void onProviderEnabled(String provider){ } public void onStatusChanged(String provider, int status, Bundle extras){ } }; public void updateWithNewLocation(Location location) { if (location != null) { Dbhelper helper = new Dbhelper(this); final SQLiteDatabase db = helper.getWritableDatabase(); long time = System.currentTimeMillis(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); curTime = df.format(time); lat = location.getLatitude(); lng = location.getLongitude(); alt = location.getAltitude(); System.out.println(lat); System.out.println(lng); System.out.println(alt); /*db.execSQL("INSERT INTO location (longitude,latitude,altitude,tgl_buat) VALUES " + "('"+lng+"','"+lat+"','"+alt+"','"+curTime+"')"); db.close();*/ /*Timer timer = new Timer(); timer.schedule(new TimerTask(){ @Override public void run(){ db.execSQL("INSERT INTO location (longitude,latitude,altitude,tgl_buat) VALUES " + "('"+lng+"','"+lat+"','"+alt+"','"+curTime+"')"); db.close(); } }, 10*60*1000, 10*60*1000);*/ } } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } </code></pre> <p>please give me a solution..thank you for feed back :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload