In android, we can easily check whether GPS is enabled in device or not using LocationManager.

Here is a simple program to Check.
GPS Enabled or Not :-
Add the below user permission line in AndroidManifest.xml to Access Location

1 <uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>

Your java class file sgould be

public class ExampleApp extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); openGPSSettings(); } private void openGPSSettings() { LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show(); }else{ showGPSDisabledAlertToUser(); } } private void showGPSDisabledAlertToUser() { // TODO Auto-generated method stub AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?") .setCancelable(false) .setPositiveButton("Goto Settings Page To Enable GPS", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int id){ Intent callGPSSettingIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(callGPSSettingIntent); } }); alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int id){ dialog.cancel(); } }); AlertDialog alert = alertDialogBuilder.create(); alert.show(); } }

The output will looks like
Android Check GPS is Enabled or Not_第1张图片Android Check GPS is Enabled or Not_第2张图片

更多相关文章

  1. Android 为图片添加文字水印
  2. Android 异步加载图片(扩展后)
  3. android获取图片文件头信息
  4. android 图片的自由缩放和旋转
  5. android裁剪图片
  6. android左右滑动翻页查看图片
  7. Android内存缓存图片的标准方法
  8. Android根据不同语言切换图片
  9. Android 图片处理工具类汇总

随机推荐

  1. [置顶] 我的Android进阶之旅------>Andro
  2. Android(安卓)快速开发数据库greenDao
  3. android CircularSeekBar
  4. Android核心分析(15)--------Android输入
  5. 使用Genymotion代替原生模拟器
  6. Android入门进阶教程(3)-linux 开发环境
  7. 移植ffmpeg中的H264解码部分到Android
  8. Android(安卓)MVP模式的化简深入理解
  9. android霓虹灯源代码――基础编
  10. Android(安卓)设计模式之MVC,从一个实例中