android - Intent 打开 GPS 并返回应用程序

标签 android android-intent gps

此代码能够转到 GPS 设置并将其打开,但按下后它并不打算返回应用程序。相反,它将我带到我的发射器的家。

        public void createDialog(){
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.gps_message);
        alert.setPositiveButton(R.string.gps_settings, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
                return;
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        alert.create();
        alert.show();
    }

最佳答案

尝试将您的起始代码更改为:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

也不要在尝试将其更改为此后调用 return:

dialog.dismiss();

调用 return 可能会关闭您的 Activity。

关于android - Intent 打开 GPS 并返回应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33172855/

相关文章:

java - 安卓 View 剪辑

android - 使用 context.startActivity 将消息直接发送到 whatsapp

android - 静态 Activity 生成器?

iOS 比较 GPS 位置

android - 在 android 中获取自己的电话号码(测试了许多问题但未解决)?

android - 使用 multidex 和 Dagger 2 时,Application 对象中缺少函数

java - 如果我想使用 Maven,是否需要安装 ADT 插件?

android - 通过 intent extras 发送大数据时出现 TransactionTooLargeException

iphone - CLLocation 的准确度有多准确?

c - 使用 libgps 未接收任何 GPS 数据