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

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

问题描述

我正在尝试使用 Android Intents在按钮上单击从Chrome(在Android上)中打开位置设置.我正在遵循条形码扫描仪"示例,并尝试以类似方式对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.

推荐答案

由于设置活动不支持 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部分

<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天全站免登陆