9

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"

or this

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.

I am attaching it to a button using href tag.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
deepankar
  • 371
  • 5
  • 13

1 Answers1

5

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.

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);
    }

}

and AndroidManifest.xml part for 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>

and, finally, "deep" link for SettingsActivity in HTML file:

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

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.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • Well my use case is for some survey/data-collection form, there is no app involved, on which I could deep link. Anyways, on seeing the answer you mentioned, I too think it won't be possible. Thanks. – deepankar Sep 12 '17 at 15:01
  • @deepankar For this case you can use [Instant Apps](https://developer.android.com/topic/instant-apps/index.html). – Andrii Omelchenko Sep 12 '17 at 15:40
  • Yes instant apps seems to be nice alternative, but they work only on Android 6.0 and above. A lot of devices fall in lower category. – deepankar Sep 12 '17 at 16:12