2017-09-07 60 views
8

我试图使用Android Intents在Chrome上打开位置设置(在Android上)。我遵循条码扫描器的例子,并尝试编码类似的方式。 对于位置我已经试过这样: -在Android上从Chrome上打开位置设置活动

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标记的按钮上。

回答

3

好像你不能从Chrome浏览器Android的意图直接打开位置设置,因为设置活动不支持BROWSABLE类别(详情看一看的Dickeylththis问题和Rafal Malekanswer)。但你可以100%通过自定义android应用程序和Deep Links来自定义Activity,支持<category android:name="android.intent.category.BROWSABLE"/>,如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> 

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

+0

那么我的使用案例是针对一些调查/数据收集的形式,没有涉及的应用程序,我可以深入链接。无论如何,看到你提到的答案,我也认为这是不可能的。谢谢。 – deepankar

+0

@deepankar对于这种情况,您可以使用[Instant Apps](https://developer.android.com/topic/instant-apps/index.html)。 –

+0

是的即时应用似乎是不错的选择,但他们只适用于Android 6.0及以上版本。很多设备属于较低类别。 – deepankar