PhoneFinder - SMS Phone Locator
Introduction
In this tutorial we will create an application called PhoneFinder. This application will illustrate how to deal with sending and receiving SMS messages. The idea of the application is that when your phone is lost or stolen you will be able to use someone else's phone to retrieve the GPS coordinates at your phone's location to help you find it.
This application needs an Activity that will allow the user to enter in the password and an IntentReceiver that will be kicked off on incoming SMS messages.
Click here to download the complete source.
Password Entry
We will use the simple dialog shown below for password entry. Once the password is correctly entered we will save a MD5 sum of the password into the SharedPreferences for the package. The preferences is an easy way to save small amounts of persistent data. It is also only accessible by classes in your package. We will take the extra precaution of saving an MD5 of the password, this way if the data was read somehow it would not reveal the plain text password unless the password is very weak (aka in the dictionary).

The layout for this dialog, main.xml, is shown below:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.c
om/apk/res/android" - android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/password_label&q
uot; - />
- <EditText android:id="@+id/password"
- android:maxLines="1"
- android:layout_marginTop="2dip"
- android:layout_width="wrap_content"
- android:ems="25"
- android:layout_height="wrap_content"
- android:autoText="true"
- android:scrollHorizontally="true"
- android:password="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/password_confirm
_label" - />
- <EditText android:id="@+id/password_confirm&qu
ot; - android:maxLines="1"
- android:layout_marginTop="2dip"
- android:layout_width="wrap_content"
- android:ems="25"
- android:layout_height="wrap_content"
- android:autoText="true"
- android:scrollHorizontally="true"
- android:password="true" />
- <Button android:id="@+id/ok"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right"
- android:text="@string/button_ok" />
- <TextView android:id="@+id/text1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
As you can see it is a very simple layout, 2 text fields, 2 input fields, a button and another text field at the end to display messages to the user. The strings are defined in the strings.xml for better multilingual support.
The code for this activity is very simple. It's job is to make sure that the password is at least 6 characters, and that the 2 password fields match. Once that is confirmed then all we need to do is save the MD5 sum of the password the user entered into the SharedPreferences.
Here is the PhoneFinder Activity:
- public class PhoneFinder extends Activity {
- private TextView messages;
- private EditText pass1;
- private EditText pass2;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- messages = (TextView) findViewById(R.id.text1);
- pass1 = (EditText) findViewById(R.id.password);
- pass2 = (EditText) findViewById(R.id.password_confirm);
- button.setOnClickListener(clickListener);
- }
- private OnClickListener clickListener = new OnClickListener() {
- if (p1.equals(p2)) {
- if (p1.length() >= 6 || p2.length() >= 6) {
- Editor passwdfile = getSharedPreferences(PhoneFinder.PASSWORD_PREF_KEY, 0).edit();
- passwdfile.putString(PhoneFinder.PASSWORD_PREF_KEY,
- md5hash);
- passwdfile.commit();
- messages.setText("Password updated!");
- } else
- messages.setText("Passwords must be at least 6 characters");
- } else {
- pass1.setText("");
- pass2.setText("");
- messages.setText("Passwords do not match");
- }
- }
- };
- }
In onCreate() we initialize the various Views that we are using in the layout and then we setup the OnClickListener object for the "ok" button. When the "ok" button is pressed we are taken down into the onClick() function that starts on line 40.
In the onClick() function we confirm that the requirements for password length is met, and we make sure that both of the text boxes match. If that all happens then we get to line 48 where we setup the SharedPreferences.Editor class. This class allows us to edit the shared preferences for this application. It is called "shared" because it is application wide preferences, there are also Activty level preferences available via Activity.getPreferences(int).
Writing to the preferences is easy once you have the Editor object. You just use one of the putX() functions to add key/value pairs and then call the commit() function to save the results.
Then on line 48 you'll see that we call the member function getMd5Hash(String) which returns the MD5 sum as a string, and we store that in the preferences. Here is the getMd5Hash(String) function:
- try {
- byte[] messageDigest = md.digest(input.getBytes());
- while (md5.length() < 32)
- md5 = "0" + md5;
- return md5;
- Log.e("MD5", e.getMessage());
- return null;
- }
- }
We use a android.security.MessageDigest
On the next page we will create the IntentReciever that will listen for SMS messages and respond to a relavent SMS message...
Handling the SMS Message
Now that the user can save the password to the preferences we will need to check all incoming SMS messages and respond to any relavent ones. We are looking for a message in the format:
SMSLOCATE:<passwo
So if a SMS messages starts with "SMSLOCATE:" and the MD5 sum of the password after the ":" matches that of the one saved earlier then we will send a text message with everything we know about the phones current location. To do this we need to setup an IntentReceiver that will respond to the "android.provider.Telephony.SM
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.c
om/apk/res/android" - package="com.helloandroid.android
.phonefinder"> - <uses-permission android:name="android.permission.RECEI
VE_SMS" /> - <uses-permission android:name="android.permission.ACCES
S_GPS" /> - <uses-permission android:name="android.permission.ACCES
S_LOCATION" /> - <application android:icon="@drawable/icon">
- <activity android:name=".PhoneFinder" android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MA
IN" /> - <category android:name="android.intent.category.
LAUNCHER" /> - </intent-filter>
- </activity>
- <receiver android:name=".FinderReceiver">
- <intent-filter>
- <action android:name="android.provider.Telepho
ny.SMS_RECEIVED" /> - </intent-filter>
- </receiver>
- </application>
- </manifest>
You'll see starting on line 4 that our application must request permission to receive SMS messages, Access the GPS device, and Access the phone's location. This is requested with the <uses-permission> tag. Then down on line 15 we must specify our receiver as "FinderReceiver" and also the intent-filter that will be checked against all intents that are broadcasted. You can see here we are only concerned with IntentBroadcasts with the action "android.provider.Telephony.SM
Now the OS will know what receiver to call for that action, so lets create the IntentReceiver called FinderReceiver:
- public class FinderReceiver extends IntentReceiver {
- @Override
- SharedPreferences passwdfile = context.getSharedPreferences(
- PhoneFinder.PASSWORD_PREF_KEY, 0);
- null);
- if (correctMd5 != null) {
- SmsMessage[] messages = Telephony.Sms.Intents
- .getMessagesFromIntent(intent);
- for (SmsMessage msg : messages) {
- if (msg.getMessageBody().contains("SMSLOCATE:")) {
- if (tokens.length >= 2) {
- if (md5hash.equals(correctMd5)) {
- LocationManager lm =
- SmsManager sm = SmsManager.getDefault();
- sm.sendTextMessage(to, null, lm.getCurrentLocation("gps").toString(),
- null, null, null);
- Toast.makeText(context, context.getResources().getString(R.string.notify_text) + to,
- Toast.LENGTH_SHORT).show();
- }
- }
- }
- }
- }
- }
- }
We start by getting the correct MD5 sum for the saved password from the SharedPreferences, we do this on lines 18-21. If there is actually a password in there then we now want to loop through all of the SMS messages that were received.
We use Telphony.Sms.Intents.getMessag
If the passwords match, then we get into the block starting on line 36. Now all we need is a String with the address to send it to, and a String with the location information. To get the location information we create a new LocationManager and simply use getCurrentLocation("gps").toSt
Note: It might be a good idea to have an option in the password entry dialog to either show or don't show the notification. If the phone was stolen it would be better to hide the notification or the theif may realize that he's being tracked and will turn off the phone, etc.
Testing this operation
Now, everything is setup. With the new version of the SDK it is very easy to send in phone calls or text messages to the emulator. It is all done using the "Emulator Control" view in Eclipse. You can add this view by going to "Window -> Show View -> Other" and then selecting the "Emulator Control" in the Android section.
So to test first you need to launch the main activity and setup a password. For this example I've entered "123456" for the password. Now you can send a text message with "SMSLOCATE:123456" as the body of the text as shown below:

And then after you send it you should see a notification like this:

There you have it! I think this is a great example of how easy it is to develop useful applications for Android. Two basic objects to handle a very useful task.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@619Apps (iPhone App Developer)'Xperia Sola' trademark hints at another possible Sony handset for the U.S. - http://t.co/atxhdfFz #iPhone #android #apps
2 hours 27 min ago -
@ayakaarchdia233 (Love)I've just received an achievement: Discriminating Shopper https://t.co/LDVOSV6I #Android #Androidgames
2 hours 27 min ago -
@DevrynBluelagon (Devryn Bluelagon)I've just received an achievement: Novice Photographer https://t.co/NpjOoveN #Android #Androidgames
2 hours 27 min ago -
@games_lma (leila marie ashley)I've just received an achievement: Persistent Shopper https://t.co/vTs6DSor #Android #Androidgames
2 hours 27 min ago -
@hawkhugh (hawkhugh)Apple's iPad3 http://t.co/T9dSUJA9 #apple #ipad3 #iphone #android
2 hours 27 min ago
Poll
Useful resources
Android Development Projects
- Android App: GPS: Form: Database: Website by danishayubb
- Jquery Mobile Project 01 by menfirst
- Simple Android App to load our Mobile Site - Hiring NOW! by steadysystems
- mobile app by ultimaterrrr
- android apps by vaneet08
- Online food shopping app (anroid) by akshaynawale
- Android eBook / reader Application by bamohriz
- Android app 50k downloads by nhcteam
- Beautiful Android Live Wallpaper by wahid2o11
- App downloads by nhcteam




Comments
دردشة سورية دردشة
دردشة سورية
دردشة لبنانية
دردشة عراقية
شات سوري
شات لبناني
دردشة سوريا
دردشة لبنان
شات سوريا
شات لبنان
دردشة السويدي
منتديات السويدي
اغاني عراقية
صور فنانين
الرياضة العراقية
شعراء العراق
نغمات عراقية
اغاني عربية
اغاني كردية
دردشة عراقية
دردشة بنات العراق
دردشة صبايا بغداد
دردشة البصره
دردشة بغداد
دردشة بغدادية
دردشة صبايا بغداد
دردشة شباب العراق
دردشة بنات العراق
دردشة الكرادة
دردشة دمشق
دردشة بيروت
دردشة حلب
دردشة حلب
دردشة عراقية
دردشة العراق
شات عراقي
جات عراقي
دردشه عراقيه
دردشة صبايا لبنان
دردشة بنات لبنان
شات صوتي | دردشة صوتية | كلام
شات صوتي
| دردشة صوتية
|
كلام
| شات كلام
|
دردشة كلام
| دردشة صوتية
|
شات صوتي
| شات
|
Chat Voice
| ahj w,jd
شات صوتي
| دردشة صوتية
|
شات صوتي
| دردشة صوتية
|
دردشه
| دردشة
|
صوتي
| صوتية
|
شات صوتي
| دردشة صوتية
|
شات صوتي
| دردشة صوتية
|
الكلام
| دردشه صوتيه
|
]v]am w,jdm
| ]v]ai w,jdi
شات صوتي
شات صوتي
شات صوتي
aglla
nice topic
شبكة اغلى
موقع نواحي - دليلك الشامل
فينك حبيبي
Johnsilva
It is nice to find a site about my interest.
My blog : Web Design Miami | Miami Web Design
I recently came across your
I recently came across your blog and have been reading along. I think I will leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
micheal
i love Android, so always
i love Android, so always look for updates. how to know if a girl likes you
Alright Stuff
I just really enjoy reading through things like this because they are so well laid out and explained. I just wish that someone could explain bank loan types to me is such a simple way.
Yes, good information you
Yes, good information you guys have here. I always prefer to read good quality contents and I think I have found it on your post here. Thanks!
Website Design Company | Website Design Firms | register website name
love it
thanks for your article its really great and useful
sportbike specifications SKEMA RANGKAIAN Electronic Circuit scolarship wireless car specifications gadget and computer car first look Motorcycle Modification sexi-stars. newlaptop circuits-audio electronic projects auto girl weapons system science kids gadget bikes walpaper mobil-wallpaper MODIFIKASI MOBIL plane-wallpaper celebsexypict artist-scandal sport-cars bikespict motor-modify sexi-model laptopharga gambar-artist fast-superbike autoshowmodel harga-kamera notebook-price diamonds-collections phones-gallery camera-prices home-pic audio-gallery autocarpict living-cares homes life-style
This excellent SMS Phone
This excellent SMS Phone Locator App content material is incredibly fantastic. The website content serves as a sensible guide as well as it is instructional. Excellent. download movies
This is exactly how decent
This is exactly how decent subject material need to be designed. The articles touches on all the relevant specifics plus it is explanatory. Marvelous. download movies
Thank you - the site very
Thank you - the site very very nice
المجتمع المصري هو مجتمع يحب الترفية حيث ان سكان مصر تصل الى تسعون مليون فرد ولذلك نحن نقدم خدمة دردشة مصرية لكل اهل مصر ام الدنيا , وتعتبر مصر متقدمة فى هذا العالم من حيث النمو فى مجالات التكنولوجيا و الكمبيوتر بنسبة كبيرة جدا لذلك نفضل دخول شات مصري اكبر تجمع بنات و شباب فى شات الحب و اجمل بنات فى دردشة دردشة الحب , اضافة الى ذلك حيث يوجد دردشة قوية تضم جميع محافظات مصر هي شات مصرية الكتابية نتمني لكم قضاء وقت ممكن فى شات الاصدقاء و احلي دردشة التعارف الذي يوجد به بنات رومانسية فى دردشة بنات مصر المصرية
شات الحب - دردشة مصرية - شات - شات مصري - شات حب - دردشة - دردشة كتابية - دردشة الحب - شات حبنا - شات حبي - شات مصرية - دردشة حب - شات بنات - دردشة مصر - دردشة بنات مصر - شات بنات مصر - شات صوتي - chat love - دردشة ياحبي - شات بنات لبنان - الحب - شات كتابي - منتدي ياحبي - شات مصر - دردشة حبنا - العاب تلبيس البنات - دردشة بنات - شات ياحبي - Chat - شات لبناني - شات كلامنجي - دردشة كلامنجي - شبكة - تصميم مواقع - تصميم - شات الاسكندرية - دردشة لبنانية - دردشة بنات لبنان - بنات لبنان - موقع شات - سعودي كول - شات سعودي كول - شات بنت مصر - شات سكس
very good
Great information you've provided us with here. Thanks so much for sharing. Nice site too...Buy Backlinks
Cellular phones are part of
Cellular phones are part of our lives. We used it much to communicate to our friends, relatives and other people. The threat that cellular phones cause cancer left us with a thought if we are now ready to say goodbye to that gadget. But we need not to do it. There are really other ways to stay away from carcinogenic substance coming from cellular phones.
pay as you go mobile broadband
thank you for information حجز
thank you for information
حجز فنادق مكة
فنادق مكة
An impressive share, I just
An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!
myegy
ماى ايجى
ماي ايجي
my egy
very nice
This is an interesting approach. Perceptions of how one is viewed certainly does influence what we say and don't say.Dui lawyers
Mediafire Movies
thank you for the pproviding full source code of this android application, now i will make this application and install it in my android phone so that no one can stole it from me.
thank you very much
mediafire movies
mediafire download
Great concept
Thanks for creating such a useful tutorial. -
Cannes Property
Really Really Thanks For This
Really Really Thanks For This Wonderful article. Its glad that nowadays also, there is some original content on the internet. Otherwise, everywhere you go you will find duplicate content. Thanks Again. Like to Read You article and blog.
download | mediafire download | all buzzy news |
good sites....
The Post Is Written in a very good manner "and it" entail Many Useful information for me. I Appreciated What You Have Done here. I am Always searching for informative information like this.Home Automation
Good work
Really a nice application developed.
But can anyone tell me, will this work on iPhone.
Thanks...
Traffic from Facebook
I visited your site & after
I visited your site & after visiting i found that it is very informational for everyone you have done really a great job thank you..fine art really DUI Lawyer
Property Investment
We will use the simple dialog shown below for password entry. Once the password is correctly entered we will save a MD5 sum of the password into the SharedPreferences for the package. The preferences is an easy way to save small amounts of persistent data. Baju Muslim It is also only accessible by classes in your package.
Such a cool one! Android
Such a cool one! Android really rocks!fnews
Thank's to all of u.
Nuclear where NYU plans to find the labor to replace the hundreds of teachers and graders who would not teach under this plan.parduotuve
it is very nice
This article has great reference value, thank you very much for sharing, I would like to reproduced your article, so that more people would see it. Thanks for this article..neato
nice blog
It is important to choose right one since the first time. Thank you for the tips.
Proper care will save money in long term.FHA Loans
PhoneFinder - SMS Phone Locator
Hi guys,
This is the first time I am visiting your blog and found it really interesting blog. I love this post becasue it contains some useful information. I must appreciate your work here. Thanks!
Joomla Website Development
All people are equal.
It is important to choose right one since the first time. Thank you for the tips.
Proper care will save money in long term.
las vegas market reports || Carmel Valley Ca Homes
شات نغم نغم شات سعودي شات
شات نغم
نغم
شات سعودي
شات سعودى
منتديات بنات
شات نغم نغم شات سعودي شات
شات نغم
نغم
شات سعودي
شات سعودى
منتديات بنات
شات نغم
شات نغم
شات الرياض شات جدة شات
شات الرياض
شات جدة
شات القصيم
شات المدينه المنوره
شات مكة
شات بريده
شات عنيزه
شات ينبع
شات تبوك
شات حائل
شات عرعر
شات الخرج
شات الطائف
شات حفر الباطن
شات الاحساء
شات القطيف
شات الخفجى
شات نجران
جيزان
شات ابها
شات الباحه
شات القريات
شات سكاكا
شات الظهران
شات الجبيل
شات مصري شات مصرى شات
شات مصري
شات مصرى
شات مصرية
دردشة مصرية
شات بحبك
دردشة مصر
منتديات بحبك
شات
دردشة
شات بنات
شات مصر
شات جده
شات جده
شات نغم الخليج
منتديات نغم الخليج
شات سعودى
شات غزل
منتديات غزل
الدلع
شات الدلع
دردشة الدلع
منتديات الدلع
كنوز
منتديات
العاب فلاش
مقاطع فيديو
كتب مجانية
دردشة الاسكندرية
شات مصر
مقاطع فيديو
منتدي
دردشة دمياط
شات صوتي
،
شات صوتي
دردشة صوتية
،
دردشة صوتية
دردشه صوتيه
،
دردشه صوتيه
حسايف
حب كام
سعودي كول
شات كام
حب كام
dgr
Every time i come here I am not disappointed, nice post.clutchpurse
Yes really..
Stunt Shades LLC provides top of the line Stunna Shades, built with high quality frames, scratch resistant lenses and very durable hinges.Stunna
Inner tube
I think more people need to read blogs like this. Its so important to know how to construct a great blog to get people interested and you've done just that.Inner tube
Here we go....
Stunt Shades LLC provides top of the line Stunna Shades, built with high quality frames, scratch resistant lenses and very durable hinges. Stunna Shades
Great article, thanks for
Great article, thanks for sharing, good luck
http://www.casinobonu.org
I think it is a kind of spy
I think it is a kind of spy tool which is very useful for some purposes.The main thing the difference between a spy tool and it.It is really a nice application of android.
clubmz reviews
Thanks, it looks great here.
Thanks, it looks great here. affiliate marketing
links building management I
links building management I would love to have one more on this topic. This is rarely discussed or incomplete but you just did fine.
A cool informative post. The
A cool informative post. The tutorial that you shared for creating an app that will help in tracing your lost mobile is really appreciable and also a useful one. Will be using the app to see whether it really works.
GSM Kampanya | Bilişim Teknoloji | Cep Telefonu | Turkcell Kampanyaları | Avea Kampanyaları | Vodafone Kampanyaları
I admire the valuable
I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!
Android Phone Tips | Android Phone | Android Tutorial | Android Tips
Great informative blog
I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I procrastinate alot and never seem to get something done. just dreams Hawaii
just dreams scam
Good information
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
Winnebago hire
Nice Blog
This is brilliant. You have a good advice for us, your readers. Thanks for sharing it.
Nice one, surely helpful.
Nice one, surely helpful. affiliate marketing
I recently came across your
I recently came across your blog and have been reading along. I think I will leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
just dreams hawaii