0

I was wondering, does anyone know how to get an address in a textview matched by the Linkify in Android and make it a clickable link?

I think I can figure out how to do this manually, but I was wondering if I have to match the address against a certain pattern so that it does this without me having to do it for Linkify?

I've seen other questions about this, but those are mostly outdated and never really got solved.

Could you point me in the right direction?

Below you can see how I do this manually with a longitude and latitude and the address itself.

mLocation.mImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent callIntent = new Intent(Intent.ACTION_VIEW);
            //callIntent.setData(Uri.parse("google.navigation:q=" + establishment.getStreet() + "+" + establishment.getHousenumber() + "+" + establishment.getPostalcode() + "+" + establishment.getCity()));
            callIntent.setData(Uri.parse("geo:" + establishment.getLongitude() + ", " + establishment.getLatitude()));

            startActivity(callIntent);

        }
    });

Thanks in advance.

Orion
  • 1,258
  • 2
  • 14
  • 32
  • use this it may help for you http://stackoverflow.com/questions/3983409/can-i-change-textview-link-text-after-using-linkify – Dinesh R Rajput Jul 08 '14 at 13:13
  • Helps me with doing it manually, but does not answer my actual question on how to get a dutch/european address matched with Linkify. – Orion Jul 08 '14 at 13:20

2 Answers2

0

Maybe this can help you: http://www.aviyehuda.com/blog/2011/01/27/android-creating-links-using-linkfy/

TextView myLocation = new TextView(this);
myLocation.setText("436 Mayfield Ave, Stanford, CA");
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);
SolArabehety
  • 8,467
  • 5
  • 38
  • 42
  • I've seen that website, but it does not find/highlight/match the Dutch/European address. E.g. Professor Granpré Molièrelaan 1 8302 BD Emmeloord. – Orion Jul 08 '14 at 13:25
0

If you look here:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/android/webkit/WebView.java#WebView.findAddress%28java.lang.String%29

You'll see that currently only US addresses are supported by Linkify.

Gets the first substring consisting of the address of a physical location. Currently, only addresses in the United States are detected, and consist of:

  • a house number
  • a street name
  • a street type (Road, Circle, etc), either spelled out or abbreviated
  • a city name
  • a state or territory, either spelled out or two-letter abbr
  • an optional 5 digit or 9 digit zip code

All names must be correctly capitalized, and the zip code, if present, must be valid for the state. The street type must be a standard USPS spelling or abbreviation. The state or territory must also be spelled or abbreviated using USPS standards. The house number may not exceed five digits.

Parameters: addr the string to search for addresses

Returns: the address, or if no address is found, null

Hope this helps anyone trying to figure the same thing out.

I guess the only thing one can do is, building your own matcher for addresses.

Orion
  • 1,258
  • 2
  • 14
  • 32
  • The webview code is relevant because that is appearantly what Linkify does. If possible, Linkify transforms your textview to a webview and applies it's styling on that. – Orion Jul 21 '14 at 14:35