在 Android 上从 Chrome 打开位置设置活动 [英] Opening Location Settings Activity from Chrome on Android

查看:37
本文介绍了在 Android 上从 Chrome 打开位置设置活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Android Intents 单击按钮从 Chrome(在 Android 上)打开位置设置.我正在关注 Barcode Scanner 示例并尝试以类似方式对 url 进行编码.对于位置,我已经尝试过:-

I am trying to open location settings from Chrome (on Android) on a button click using Android Intents. I am following the Barcode Scanner example and tried encoding the url similar way. For location I have tried this:-

const uri = "intent://com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS#Intent;action=com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS;end"

我也试过用这个打开设置:-

I also tried opening settings using this:-

const uri = "intent://ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"

或者这个

const uri = "intent://android.provider.Settings.ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"

但似乎没有任何效果.任何帮助表示赞赏.

But nothing seems to work. Any help is appreciated.

我使用 href 标签将其附加到按钮上.

I am attaching it to a button using href tag.

推荐答案

似乎您无法使用 Chrome 直接从 Android Intents 打开位置设置,因为设置活动不支持 BROWSABLE 类别(有关详细信息,请查看 这个关于Dickeylth答案 Rafal Malek).但是您可以 100% 通过自定义 android 应用程序和 深层链接 使用 <category android:name="android.intent.category.BROWSABLE"/> 支持自定义活动,例如 那个教程.

Seems you can't open Location Settings directly from Android Intents with Chrome because Settings Activities didn't support BROWSABLE category (for details take a look at this question of Dickeylth and answer of Rafal Malek). But You can 100% do this via custom android application and Deep Links to custom Activity with <category android:name="android.intent.category.BROWSABLE"/> support, like in that tutorial.

在这种情况下,您的应用程序 SettingsActivity 代码应如下所示:

In that case your application SettingsActivity code should be like:

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
    }

}

AndroidManifest.xml 部分用于 SettingsActivity

<activity android:name=".SettingsActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE"/>
        <data
            android:host="open.location.settings"
            android:scheme="http"/>
    </intent-filter>

</activity>

最后,HTML 文件中 SettingsActivity 的深层"链接:

and, finally, "deep" link for SettingsActivity in HTML file:

<a href="http://open.location.settings">Open Location Settings</a>

看来,如果您不想在用户端安装应用程序,您也可以在 免安装应用.您可以在此处找到有关 Instant App 链接的详细信息.

Seems, if you don't want to install app on user side, you can also do this in Instant Apps. Details for links to Instant App you can find here.

这篇关于在 Android 上从 Chrome 打开位置设置活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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