如何启用位置编程访问的机器人? [英] How to enable Location access programatically in android?

查看:149
本文介绍了如何启用位置编程访问的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与地图相关的Andr​​oid应用程序,我需要检查的位置访问允许与否客户端的开发,如果定位服务不支持显示对话框提示。

I am working on map related android application and i need to check location access enable or not in client side development if location services is not enable show the dialog prompt.

如何启用位置访问以编程的机器人?请给我一些建议和任何实例源。

How to enable "Location access" Programatically in android? Please give me some suggestion and any example source.

推荐答案

使用低于code检查。如果它被禁用,对话框将产生

Use below code to check. If it is disabled, dialog box will be generated

public void statusCheck()
        {
            final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

            if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
                buildAlertMessageNoGps();

            }


        }
         private void buildAlertMessageNoGps() {
                final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
                       .setCancelable(false)
                       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                           public void onClick(final DialogInterface dialog,  final int id) {
                               startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                           }
                       })
                       .setNegativeButton("No", new DialogInterface.OnClickListener() {
                           public void onClick(final DialogInterface dialog, final int id) {
                                dialog.cancel();
                           }
                       });
                final AlertDialog alert = builder.create();
                alert.show();

            }

这篇关于如何启用位置编程访问的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆