autoLink for map not working - android

I have the following TextView in my XML layout file:-
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/autolink_test"
android:autoLink="all"
/>
The string autolink_test contains a phone number, an email address, a website address and a physical geographical address.
While the first three are showing up correctly as clickable autolinks, the address does not. Only the zipcode part shows up as an autolink... and that too as a phone number! (When I click it, the phone dialer starts up with that number).
Any help would be appreciated.

Alternative to it, in case if autolink doesn't work
Add links to your texview . Get it underline as folows :
SpannableString spanStr = new SpannableString(buf.toString());
spanStr.setSpan(new UnderlineSpan(), 0, spanStr.length(), 0);
iTextView.setText(spanStr);
Use the following code to open it with map app on click as follows :
Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="
+iTextView.getText().toString()));
startActivity(geoIntent);

OK, I figured out what was causing the problem. Just thought I will leave the answer here in case someone else runs into the same problem.
If the street address is not properly capitalized, it is not read properly as the address!
Here is my XML autolink_test string:
<string name="autolink_test">Name: New York Times \n
Email: public#nytimes.com \n
Phone: 212-556-7652 \n
Address: 620 Eighth Avenue New York, NY 10018 \n
Address: 620 Eighth avenue New York, NY 10018 \n
Website: http://www.nytimes.com
</string>
The first address shows up correctly as an autolink.
The second one (with a small 'a' in 'avenue') does not show up correctly.
This seems a little strange to me as the google maps website certainly doesn't care about such niceties.
Anyways, so here it is :-)

Related

Phone numbers links not working on Android 9

I want to have my phone number to be clickable, right now my current solution:
final SpannableString msg = "Contact us: test#t.t or call: 5008 878 6578"
Linkify.addLinks(msg, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
textView.setText(msg);
This works fine for Android 8.1 and below but not for Android 9 (email is clickable so the problem is only with number phone)
I've tried already doing it with XML layouts or with
textView.setAutoLinkMask(Linkify.PHONE_NUMBERS)
And the output is the same, phone number is not clickable.
How to fix it on Android 9?
The mask Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS seems correct, according to the documentation - but I would not recognize something alike 5008 878 6578 as a valid phone number - and I definitely could not dial it, if I would click it... so most likely the sPhoneNumberMatchFilter might be at fault.
Manually building the desired Spannable with the tel://50088786578 might be an easy solution; adjusting the sPhoneNumberMatchFilter might be the other option... also .addLinks() permits this, with argument matchFilter.
Are you certain that you are running with the same Locale on Android 9.0? This should be where the regex pattern to match for may come from, because those formats count towards localization.

How to make phone numbers clickable in a textview in Android

I have a text view that contains an email and a phone number. My desired effect is that when the user taps the email, it opens the default emailing application and when the user taps the phone number, the application pulls it up in the dialer. With the code below:
XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/careers_guidance"
android:id="#+id/careers_guidance_text"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="5dp"
android:linksClickable="true"
android:textColorLink="#0000EE"
android:autoLink="all"/>
Java:
careersGuidance = view.findViewById(R.id.careers_guidance_text);
careersGuidance.setText(Html.fromHtml("<p>Help with choosing the right course and with thinking about where this might take you in the future.</p>" +
"<p>Tel: 01274 433043</p>Email: careers#bradfordcollege.ac.uk"));
When I run my application, only the email is clickable and works the way I want it to work, the phone number isn't clickable or highlighted.
However, I have noticed that if I remove the email address from the setText java code, and run the application. The phone number becomes blue and underlined as if it is clickable, but when I tap it, nothing happens.
How can I get this working?
Also, I have CALL_PHONE permissions granted in my manifest file, and also on my emulator device.
From the email (.ac.uk), I suppose that you are from UK. You just need to add your country phone number prefix to replace 0, which is +44. And you don't need to use Html.fromHtml.
careersGuidance.setText("Help with choosing the right course and with thinking about where this might take you in the future.\n\nTel: +441274433043\n\nEmail: careers#bradfordcollege.ac.uk");
In your xml, you just need this property
android:autoLink="all"
You have to add your country code into Tel no.
Like this :
careers_guidance_text.setText(Html.fromHtml("
<p>Help with choosing the right course and with thinking about where this might take you in the future.</p>"
+"<p>Tel: +441274 433043</p>
Email: <a href=\"mailto:careers#bradfordcollege.ac.uk\">
careers#bradfordcollege.ac.uk</a>"));
Also have to add CALL PHONE Permission in android manifest file.
uses-permission android:name="android.permission.CALL_PHONE".

Display unicode character, Android back arrow, in toast message

I'm trying to display this Unicode character in a Toast message:
http://graphemica.com/%E2%AE%8C
It is embedded in a Xml file that contains all the strings of the Android application, like this
<string name="back_press">Click again ⮌ to exit</string>
The message shown from the Toast is the one in the image
toast message
Can you help me to solve this problem?
Thank you in advance.
You should use the Unicode character, in your case U+2B8C and replace U+ by 1x, but you should look for another icon because that one doesn't exist, search one you like in here.
For this example I've used the back arrow:
int unicode = 0x2B05;
String textIcon = new String(Character.toChars(unicode));
Toast.makeText(getApplicationContext(), "Your text here" + textIcon, Toast.LENGTH_LONG).show();
And that should view your icon.

Russian text is not working in Android game when ported from iOS using Apportable SDK

I have successfully ported our game to Android from iOS using Apportable starter SDK.
I have come across a issue in which the device is decoding Russian text of the game , i have included screen shots and where i have given such Russian texts in xcode.As you see from the i have typed the word "Test" in English which is displayed properly and whereas the Russian text is displayed in some form of code.
NSArray *objects = [NSArray arrayWithObjects:#"\n Test Разъезжая по сказочным землям и устраивая веселые дискотеки, я добрался до Пушляндии. Я много слышал о веселых и дружных жителях этой страны - Пушистиках. Узнав о моем появлении, они шумной толпой прибежали на мою вечеринку..."];
Stack overflow is not allowing me to add screenshots so i am adding links.The first screenshot shows the way i want the text to display in android adb second screenshot shows the current way its displayed.
I will provide more detailed description or code if required.
Screenshot iOS: http://imgur.com/IX1ALye
Screenshot Android: http://imgur.com/oJmAoMO
Maybe i will be captain obviously it`s looking like file encoding error after port. Russian texts sometimes ussing cp-1251 encoding not utf. I hope i will help you to find solution.
P.s Sorry i dont have enought reputation to add comment so i post it like answer.

linking map address using linkify in android

The following code don't work-
TextView myLocation = new TextView(this);
myLocation.setText("Sodala, Jaipur, Rajasthan, IN");
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);
It seems your address is too vague for Linkify. I am unaware of what addresses look like in India (if they are different at all), so consider New York in the US:
myLocation.setText("New York, NY 34 Maint St New York, NY");
"New York, NY" alone is not a valid map address for Linkify.
You can try to set your own pattern, by following an example here to match anything with ", IN".
Here is a simplified version of addLinks with a custom pattern.:
Pattern pattern = Pattern.compile(".*", Pattern.DOTALL);
addressTextView.setText(address);
Linkify.addLinks(addressTextView, pattern, "geo:0,0?q=");
I use this for german and US addresses, since google-maps is pretty smart when searching an address other localities should work find too.
This highlight's all the content's of the TextView which fits my use-case. If the address is somewhere inside of the string a smarter pattern needs to be applied here.
you try
http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/
// Recognize all of the default link text patterns
Linkify.addLinks(text, Linkify.ALL);
or
http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/
TextView myCustomLink2 = new TextView(this);
Pattern pattern2 = Pattern.compile("[a-zA-Z]+");
myCustomLink2.setText("press one of these words to search it on google: Android Linkify dzone");
Linkify.addLinks(myCustomLink2,pattern2, "http://www.google.ie/search?q=", myMatchFilter, null);

Categories

Resources