我正在开发一款使用Google Play服务的应用.在某些手机上,客户端为位置返回null.发生这种情况是因为在Google设置中未启用locaiton选项,如附带的图片中所示.
如何编程检查Android应用程序中是否启用了谷歌设置位置?
http://www.cnet.com/how-to/explaining-the-google-settings-icon-on-your-android-device/
解决方法
LocationManager lm = null; boolean gps_enabled,network_enabled; if(lm==null) lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try{ gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); }catch(Exception ex){} try{ network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); }catch(Exception ex){} if(!gps_enabled && !network_enabled){ dialog = new AlertDialog.Builder(context); dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled)); dialog.setPositiveButton(context.getResources().getString(R.string.open_location_settings),new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface,int paramInt) { // TODO Auto-generated method stub Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); context.startActivity(myIntent); //get gps } }); dialog.setNegativeButton(context.getString(R.string.Cancel),int paramInt) { // TODO Auto-generated method stub } }); dialog.show(); }