Discussing the nuts and bolts of software development

Friday, July 17, 2009

 

Here I am!

This application allows you to send URL link with your location through SMS message. Receiver will be able to see your location on the map(Google Maps) by simply clicking on the link. First thing we need to do is to get our location using GPS. Android SDK has set of classes and interfaces which makes dealing with location services quite easy. Another positive thing is that SDK is well documented. We need to get an instance of LocationManager:
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Now that we have location manager we need to request location updates from it. The location is requested using requestLocationUpdates method, it registers the current activity to be notified periodically by the named provider. In our case provider is GPS. For tracking location changes we are using LocationListener which is for receiving notifications from the LocationManager when the location has changed.

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, 
                new LocationListener() {
                    public void onLocationChanged(Location location) 
                    {
                        double lat = location.getLatitude();
                        double lng = location.getLongitude();                        

                        latitude.setText( Double.toString( lat ) );
                        longitude.setText( Double.toString( lng ) );
                    }

                    public void onProviderDisabled(String provider){}
                    public void onProviderEnabled(String provider){}
                    public void onStatusChanged(String provider, int status,Bundle extras){}
        });

Just getting last known location...
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Good! We got the location. Now we just need to generate the URL and send SMS. Android offers full access to SMS functionality from within your applications with the SMSManager. We are geeting a reference to the SMS Manager using the static method SmsManger.getDefault. For sending SMS message use sendTextMessage, which allows you to send SMS message by specifying text message and receiver's phone number.
final SmsManager sm = SmsManager.getDefault();
String phoneNumber = number.getText().toString();
String URL = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=";
URL += latitude.getText() + "," + longitude.getText(); 
sm.sendTextMessage(phoneNumber, null, URL, null, null);
That's it! Just one note - in order to send SMS message and request GPS location application require following two permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS"/> 

Thanks to my friend Aaron Olson from Macadamian for the help in testing this code.

Source

Labels: , ,


Comments:
I am sure that these advices will be useful for students. You can use this source in order to get high quality essay.
 
Thanks for putting this content here as I find it really helpful. Moreover, if you are interested in reading mortgage rates Florida then check this post.
 
Thanks for sharing this.,
Leanpitch provides online training in CSPO during this lockdown period everyone can use it wisely.
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.
CSPO online certification

CSPO certification cost
 
Hi, This is Beverly Clay representation of Wuxi Jiayou Packaging Materials Co., Limited. We are the provider of quality stretch film jumbo roll manufacturer in china. We take about the client products safety so we produce colored stretch film, Stretch film hand roll, and many other products for packaging.

 
Thanks for sharing very informative info,
 
Found your post interesting to read. I cant wait to see your post soon. Good Luck for the upcoming update.This article is really very interesting and effective.

greatpeople me kroger login employee portal
 
Thank you for this post. Good luck.


kroger w2

 
But first you need the data set containing the numbers or email addresses of the receipt.
 
Hello. I am glad to visit your blog. I love reading interesting articles and learning new information. I recently found who can help me write my discussion board post . It helps me be a better student. Now I can get everything I need.
 
Convenient for travel
 
As a trainer at Wolf Careers, I specialize in equipping individuals with the necessary skills to become a certified Salesforce Business Analyst. With a focus on delivering high-quality training and job placement services, I am dedicated to helping professionals launch and grow their careers in the Salesforce industry. My goal is to help individuals achieve their salesforce business analyst certification and secure employment opportunities in the USA.
 
Very interesting,good job and thanks for sharing such a good blog.your article is so convincing that I never stop myself to say something about it.You’re doing a great job.Keep it up پنجاب لائسنس DLIMS

 
I want to encourage you conttinue your great writing, have a nice day!
 
I think this will really help many people with this knowledge that you have shared.
 
success is always for you, yes!
 
Hello friends, its great post about tutoring and completely defined,
 
With the SMSManager, Android provides complete SMS capabilities from within your applications. The meta description is just the start of the journey when it comes to retrieving a reference to the SMS Manager through the use of the static method Sms Manger.getDefault!"I appreciate you giving your knowledge! Continue your fantastic effort! Keep on sharing. I invite you to browse my website.
 
Very efficiently written information.

 
It will be valuable to everyone who utilizes it, as well as yours truly.
 
I envy your piece of work, appreciate it for all the good content.
 
Your writing style has been amazed me. Thank you, quite great article.
 
Thanks for sharing amazing information !!!!!! Please keep up sharing.
 
Hi! I am very happy, that I visited this website. Its alot of interesting stuff here.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?