Skip to content

Instantly share code, notes, and snippets.

@t-mat
Created December 7, 2011 08:40
Show Gist options
  • Select an option

  • Save t-mat/1442028 to your computer and use it in GitHub Desktop.

Select an option

Save t-mat/1442028 to your computer and use it in GitHub Desktop.
android : check gps enable
// This application needs
//
// <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
//
// in AndroidManifest.xml : <manifest> section.
package com.example.my.checkgps;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.content.Context;
import android.location.LocationManager;
public class HelloAndroidMark2Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean gpsProviderEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
String s;
if(gpsProviderEnabled) {
s = "GPS : enable";
} else {
s = "GPS : disable";
}
TextView tv = new TextView(this);
tv.setText(s);
setContentView(tv);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment