Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void cekGPS() {
- try {
- // pengecekan GPS hidup / tidak
- LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
- if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle("Info");
- builder.setMessage("Anda akan mengaktifkan GPS?");
- builder.setPositiveButton("Ya",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- startActivity(intent);
- }
- });
- builder.setNegativeButton("Tidak",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- dialog.dismiss();
- }
- });
- builder.create().show();
- }
- } catch (Exception e) {
- }
- int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
- // menampilkan status google play service
- if (status != ConnectionResult.SUCCESS) {
- int requestCode = 10;
- Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,requestCode);
- dialog.show();
- } else {
- // google play service tersedia
- try {
- LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
- // membuat kriteria untuk menampung provider
- Criteria criteria = new Criteria();
- // mencari provider terbaik
- String provider = locationManager.getBestProvider(criteria, true);
- // mendapatkan lokasi terakhir
- Location location = locationManager.getLastKnownLocation(provider);
- if (location != null) {
- onLocationChanged(location);
- }
- locationManager.requestLocationUpdates(provider, 5000, 0, this);
- } catch (Exception e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement