我正在尝试使用 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
类别(有关详细信息,请查看 this 的 Dickeylth 问题和 answer 的 Rafal 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/