ampersand in text message - sms sending android - android

So here's my problem.
I have a Timer which is supposed to send a SMS every X seconds.
And i want the text message to be the current GPS location of the user.
So, i want to send a kind of Google Maps URL, using the GPS coordinates i get, and adding some markers, maptype, size.... for the map.
To do that, i need to use the character "&" in the URL. In order to get something like that :
http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=roadmap
(ie : https://developers.google.com/maps/documentation/staticmaps/?csw=1#URL_Parameters)
But, when i want to use this kind of URL, using "&" in my text message of the SMS. The SMS is never sent. When i remove every part containing the "&", it's working fine.
I tried to use "&amp ;" instead of "&". Still doesn't work.
Here's my SMS manager to send the SMS :
smsManager.sendTextMessage(INT, null, "Alert - RED AREA \n TIME : " + current date + " \n Lat: " + latitude + " \n Long: " + longitude + "Link Maps : http://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude +"&zoom=12&size=400x400&maptype=satellite", null, null);
The code above, doesn't send any messages.
But this one does :
smsManager.sendTextMessage(INT, null, "Alert - RED AREA \n TIME : " + current date + " \n Lat: " + latitude + " \n Long: " + longitude + "Link Maps : http://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude, null, null);
Any ideas ?
Thanks !

Use "%26" instead of "&" or "&amp", the URL will still parse and the SMS will construct properly

The simplest solution would be to think of some sort of special character (or string) that you would use to replace the '&' character in your string.
You would go through your source string and replace every occurence of '&' with the special string (representing '&').
The reversed mechanism should be implemented in the receving side.
BUT BE CAREFUL! you need to choose your special string carefully! Because if you choose a string that could normally occur in your source string, the receiver would insert a fake '&' characters.
If this solution is not good enough, let me know... I have had a similar problem in one of my apps, and found a workaround without replacing a character with something else.

Related

String objects with various Hyperlinks in Textview?

I have a String objects that contain hyperlinks which I'm trying to make clickable in a Textview, here's an example:
String descrption = "\"Cardano is a decentralised platform" +
" that will allow complex programmable transfers of" +
" value in a secure and scalable fashion. It is one" +
" of the first blockchains to be built in the highly" +
" secure Haskell programming language. Cardano is developing" +
" a smart contract platform" +
" which seeks to deliver more advanced features than any protocol previously developed." +
" It is the first blockchain platform to evolve out of a scientific philosophy and a research-first driven approach." +
" The development team consists of a large global collective of expert engineers and researchers.\\r\\n\\r\\n" +
"The Cardano project is different from other blockchain projects as it openly addresses the need for regulatory oversight whilst maintaining" +
" consumer privacy and protections through an innovative software architecture.";
TextView textView = findViewById(R.id.description_textview);
Linkify.addLinks(textView, Linkify.WEB_URLS);
But this is how it comes out:
How can I get the hyperlinks to format correctly?
I've managed to get it working with the following code:
descrption= descrption.replaceAll("\\r\\n", "<p>");
Spanned spanned= Html.fromHtml(descrption);
textView .setText(spanned);
textView.setMovementMethod(LinkMovementMethod.getInstance());

Using Google Places API?

First of all I want to say that I have checked all the related answers to this question and none of them is working for me as I think they are now old and doesn't seem to work with the new apis.
How to use Google Places API in Android?
Can i use google Places API in android?
Google Places API - android
Above are the few links that I have checked.
I am trying to get the nearby restaurants using the places api in which radius will be defined by user using a seekbar.
Here is how I am creating my request
private String getUrl(double latitude, double longitude, String nearbyPlace, int radius) {
StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/search/json?");
googlePlacesUrl.append("location=" + latitude + "," + longitude);
googlePlacesUrl.append("&radius=" + radius);
googlePlacesUrl.append("&type=" + "restaurants");
googlePlacesUrl.append("&sensor=true");
googlePlacesUrl.append("&keyword=" + nearbyPlace);
googlePlacesUrl.append("&key=" + "xxxxxxxxxxxxxx");
Log.d("getUrl", googlePlacesUrl.toString());
return (googlePlacesUrl.toString());
}
I pass the above created url to an asynctask to fetch the result from it.
But everytime I am trying to request I get the below error.
{ "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 103.226.226.47, with empty referer", "html_attributions" : [], "results" : [], "status" : "REQUEST_DENIED"}
I have signed up for google cloud platform too in case that is the issue but that doesn't help either.
I solved the problem myself.Everything I did was correct. Problem was that google places api says it takes 5 minutes after enabling to get activated. But in real it took more time than that. So I was actually checking after almost exact 5 minutes and it was not working. I left it for about 2-3 hours and it started working after that.

How to log on Fabrics a long message

I'm trying to write a long text log message on Fabrics system (Android), like this:
Answers.getInstance().logCustom(new CustomEvent("Request:" + requestUrl + "\nResponse:" + json));
The message become cut, and can't find a way to expand it:
Even when the message is added as a custom attribute, like #Alexizamerican suggested,
Answers.getInstance().logCustom(new CustomEvent("Requests"))
.putCustomAttribute("Request", requestUrl + "\nResponse:" + json)
it stays cut in the Events Dashboard, see picture below:
How to see the whole message?
It's best to include longer messages as custom attributes of an event, rather than in the event name. For example:
Answers.getInstance().logCustom(new CustomEvent("Requests"))
.putCustomAttribute("Request", requestUrl + "\nResponse:" + json)
Check out
https://docs.fabric.io/android/answers/answers-events.html#custom-attributes
for more details.

Html.fromHtml("message.") getting error android

i am getting an error when converting my message into html on run time.
according to my requirement, i am using this code
messageTextView.setText(Html.fromHtml((message2
) + "          " +
"       "));
for some space at runtime.but if message2 contain dot(.) in the last of message its showing as a clickable link so i used like this-
messageTextView.setText(message2+ Html.fromHtml(
" " + "          " +
"       "));
but its getting error in some devices.not showing any space at run time.How to resolved this?

Does Android TTS support Speech Synthesis Markup Language?

Passing the following SSML (Speech Synthesis Markup Language) document to the com.svox.pico TextToSpeech engine resulted in a reading of the XML body but no control from the phoneme element or the emphasis element. This result (no apparent SSML control) is the same on a Nexus One running Android 2.2 as well as on the emulator running an AVD with SDK level 8.
String text = "<?xml version=\"1.0\"?>" +
"<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xsi:schemaLocation=\"http://www.w3.org/2001/10/synthesis " +
"http://www.w3.org/TR/speech-synthesis/synthesis.xsd\" " +
"xml:lang=\"en-US\">" +
"tomato " +
"<phoneme alphabet=\"ipa\" ph=\"t&#x259;mei&#x325;&#x27E;ou&#x325;\"> tomato </phoneme> " +
"That is a big car! " +
"That <emphasis> is </emphasis> a big car! " +
"That is a <emphasis> big </emphasis> car! " +
"That is a huge bank account! " +
"That <emphasis level=\"strong\"> is </emphasis> a huge bank account! " +
"That is a <emphasis level=\"strong\"> huge </emphasis> bank account!" +
"</speak>";
mTts.speak(text, TextToSpeech.QUEUE_ADD, null);
Does any Android TTS engine support any of the SSML elements?
I've been experimenting with SSML and it seems that the TTS engine wraps its input automaticly with the root <speak> element, so if you leave it out, then it works fine and you don't get a parser error.
Example:
String text = "Testing <phoneme alphabet=\"xsampa\" ph=\""{k.t#`\"/>.";
mTts.speak(text, TextToSpeech.QUEUE_ADD, null);
The answer seems to be "sort of". Not all the SSML tags are supported yet, but some test examples of the use of the <phoneme> tag are at https://android.googlesource.com/platform/external/svox/+/89292811b7fe82e5c14fa13942779763627e26db
Though the test examples produce the desired speech output, they also produce XML parser error messages in logcat. I've opened an issue about these seemingly incorrect error messages at the Android issue tracker (issue 11010).
It does appear that android.speech.tts at SDK level 23 supports a subset of SSML. Speech text can be wrapped in <speak> tags, and <say-as> is observed, while <break> is not. There is no documentation regarding SSML support.

Categories

Resources