【问题标题】:Opening Location Settings Activity from Chrome on Android从 Android 上的 Chrome 打开位置设置活动
【发布时间】:2018-02-16 09:01:30
【问题描述】:

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

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

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

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"

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

我正在使用 href 标记将它附加到按钮上。

【问题讨论】:

    标签: android google-chrome web browser location


    【解决方案1】:

    您似乎无法使用 Chrome 直接从 Android Intents 打开位置设置,因为设置活动不支持BROWSABLE 类别(有关详细信息,请查看Dickeylth 的this 问题Rafal Malek 和answer @)。但是您可以 100% 通过自定义 android 应用程序和 Deep Links 到带有 <category android:name="android.intent.category.BROWSABLE"/> 支持的自定义 Activity 来做到这一点,就像在 that 教程中一样。

    在这种情况下,您的应用程序 SettingsActivity 代码应该是这样的:

    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 的“深层”链接:

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

    看来,如果您不想在用户端安装应用程序,您也可以在Instant Apps 中执行此操作。您可以找到here 的即时应用链接的详细信息。

    【讨论】:

    • 好吧,我的用例是一些调查/数据收集表格,不涉及应用程序,我可以在其上进行深度链接。无论如何,看到你提到的答案,我也认为这是不可能的。谢谢。
    • @deepankar 对于这种情况,您可以使用Instant Apps。
    • 是的,即时应用似乎是不错的选择,但它们仅适用于 Android 6.0 及更高版本。许多设备属于较低类别。
    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 2012-05-30
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多