本文介绍了Android:检查是否启用google设置位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究使用谷歌播放服务的应用程序。在某些电话上,客户端返回空位置。发生这种情况是因为locaiton选项未在谷歌设置中启用,如附图所示。



如何以编程方式检查在Android应用程序中是否启用了谷歌设置位置?

http://www.cnet.com/how - 解释方式

$ p> LocationManager lm = null;
布尔值gps_enabled,network_enabled;
if(lm == null)
lm =(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
尝试{
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch(Exception ex){}
try {
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex){}
$ b $ 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(){
$ b $ @Override
public void onClick(DialogInterface paramDialogInterface ,int paramInt){
// TODO自动生成方法存根
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(myIntent);
// get gps
}
});
dialog.setNegativeButton(context.getString(R.string.Cancel),new DialogInterface.OnClickListener(){
$ b @Override
public void onClick(DialogInterface paramDialogInterface,int paramInt) {
// TODO自动生成的方法存根

}
});
dialog.show();


$ / code>

ACTION_LOCATION_SOURCE_SETTINGS显示用户,允许配置当前位置的设置来源。


I'm working on an app that uses google play services. On Some phones, the client returns null for location. This happens because the locaiton option is not enabled on google setting as in the pic attached.

How to programatically check if google settings location is enabled in an android app ?

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), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                // TODO Auto-generated method stub

            }
        });
        dialog.show();

    }

ACTION_LOCATION_SOURCE_SETTINGS shows the user, settings to allow configuration of current location sources.

这篇关于Android:检查是否启用google设置位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:18