我向用户显示了启用gps设置的提示,但是如何检查用户是否真的启用了手机上的gps位置?
@H_301_6@private static void showGPSDisabledAlertToUser() { // TODO Auto-generated method stub AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ChatSDK.getSDKInstance().activity); 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); ChatSDK.getSDKInstance().activity.startActivity(callGPSSettingIntent); } }); // alertDialogBuilder.setNegativeButton("Cancel",// new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog,int id) { // dialog.cancel(); // } // }); AlertDialog alert = alertDialogBuilder.create(); alert.show(); } }
最佳答案
@H_301_6@ if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)) .isProviderEnabled(LocationManager.GPS_PROVIDER)) { //prompt user to enable gps }else{ //gps is enabled }