0

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 !

Mylo Raf
  • 1
  • 1
  • 1

2 Answers2

2

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

paddyflah
  • 21
  • 3
0

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.

Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
  • Nice way as well ! Thank you :) Using &amps; works fine too. In fact, the problem was about the maximum number of characters authorized. It can't be over 160 and my total amount of characters was about 180-190. Working on implementing a shortener for the url links now ! – Mylo Raf Jun 17 '14 at 13:25