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

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)Intent Filter应用方式讲解
  2. 为什么Android没有iOS那么顺滑
  3. [Android] 将Android工程做成jar包和资源
  4. 【乱】乱,乱,乱,android真乱!
  5. Android开发之旅:android架构
  6. Android内存管理机制
  7. Android(安卓)匿名共享内存C接口分析
  8. Android源代码下载指南(图解)
  9. android的aidl机制案例
  10. Android(安卓)使用Vitamio打造自己的万能