Open app when detecting a geo Uri on Android, get values

1

How can you make the app open? by clicking on a link from the web browser, chrome, firefox ... a link of type geo:... Geo URI scheme

geo:37.786971,-122.399677

What I have:

Capture when the user clicks on a geo:... link in their browser

<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:scheme="geo"/>
</intent-filter>

I still need to process the intent from my app and separate the values, latitude, longitude

    
asked by Webserveis 14.11.2017 в 17:28
source

1 answer

3

You can do it this way by receiving the data in your Activity :

 Intent bundle = getIntent();
 String dataReceived = bundle.getData().toString();

 //Elimina el esquema, y crea un array con los valores. 
 String[] latlong = dataReceived.replace("geo:","").split(",");

Gets latitude and longitude data as values% String :

 String lat= latlong[0];
 String lon = latlong[1];

Later you can change them to double , by Double.parseDouble() :

 double latitude=  Double.parseDouble(lat);
 double longitude=  Double.parseDouble(lon);

To obtain the values:

latitude:  37.786971 
longitude: -122.399677
    
answered by 14.11.2017 / 20:07
source