android - 在 Android 上从 Chrome 打开位置设置 Activity

标签 android google-chrome web browser location

我正在尝试使用 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 标签将它附加到按钮。

最佳答案

您似乎无法使用 Chrome 直接从 Android Intents 打开位置设置,因为设置 Activity 不支持 BROWSABLE 类别(有关详细信息,请查看 thisDickeylth 问题和 answerRafal Malek 问题)。但是您可以 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>

最后,SettingsActivity 的“深层”链接在 HTML 文件中:

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

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

关于android - 在 Android 上从 Chrome 打开位置设置 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46099467/

相关文章:

android - 如何 Hook 我的Android应用程序的系统调用(非root设备)

java - 无法识别阿拉伯字符

html - 用于 HTML5 的 FFMPEG H.264 编码(以及最终的 MPEG-DASH)

android - RecyclerView.Adapter 中的 ViewHolder 不特定于位置

javascript - 开发 chrome 扩展

html - 不透明度 < 1 的元素不在第一列时不会在 chrome 中呈现

javascript - react native 文本输入禁用选择输入的文本

php - 如何使用 Yii2 检查数据库中的数据是否存在?

java - 如何使用 java 通过 Web 服务器发送 R 文件?

android - 如何找到被点击的地方或路径 VectorDrawable