Sei sulla pagina 1di 6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


10

More

Next Blog

Create Blog

Sign In

Start Free Download


Start Tracking your Package w/ Link Get Package Tracer for Free - Now!

Ads by Google

Android Reading Inbox SMS


Sample source code for reading inbox sms

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

Send Free SMS


SMS to Mobile
SMS Sending
Menu

Android LED
Notification
Android RTP Sender &
VLC Receiv er
Audio Record&Play

public class SMSRead extends Activity {

Background Serv ice


Battery Tem perature

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
while (cur.moveToNext()) {
sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";
}
view.setText(sms);
setContentView(view);
}

Block incom ing call


Hom e Screen Widget
Reading SMS Inbox
SMS Receiv ing BroadcastReceiv er

Follow ers

Join this site


w ith Google Friend Connect

Members (90) More

Add below permission to AndroidManifest.x ml

<uses-permission name="android.permission.READ_SMS" />

Already a member? Sign in

+10 Recommend this on Google

36 comments :
Krishna February 1 5, 2 01 1 at 1 0:4 4 AM
Hi
Nice tutorial sav e m y tim e .But i hav e one question how we read the new incom ing m essage.I want to read the
new incom ing m essages any idea about this
Reply
Replies

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

1/6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


Unknown February 2 8, 2 01 2 at 9 :54 PM
Make BroadCast Receiv er for incom ing m essage.
Reply

Gopal February 1 5, 2 01 1 at 1 2 :50 PM


Hi
Please tell m e how to v iew the new incom ing m essage in android
Reply

SIVA August 1 3 , 2 01 1 at 9 :3 1 AM
Setup the Android Manifest with the perm ission and the Intent Receiv er

Code a sim ple Intent Listener


package org.apache.sm s;
im port
im port
im port
im port
im port
im port
im port
im port

android.app.NotificationManager;
android.content.Context;
android.content.Intent;
android.content.IntentReceiv er;
android.os.Bundle;
android.prov ider.Telephony ;
android.util.Log;
android.telephony .gsm .Sm sMessage;

public class SMSApp extends IntentReceiv er {


priv ate static final String LOG_TAG = "SMSApp";
/* package */ static final String ACTION =
"android.prov ider.Telephony .SMS_RECEIVED";
public v oid onReceiv eIntent(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
StringBuilder buf = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Sm sMessage[] m essages = Telephony .Sm s.Intents.getMessagesFrom Intent(intent);
for (int i = 0; i < m essages.length; i+ + ) {
Sm sMessage m essage = m essages[i];
buf.append("Receiv ed SMS from ");
buf.append(m essage.getDisplay OriginatingAddress());
buf.append(" - ");
buf.append(m essage.getDisplay MessageBody ());
}
}
Log.i(LOG_TAG, "[SMSApp] onReceiv eIntent: " + buf);
NotificationManager nm = (NotificationManager) context.getSy stem Serv ice(
Context.NOTIFICATION_SERVICE);
nm .notify WithText(1 2 3 , buf.toString(),
NotificationManager.LENGTH_LONG, null);
}
}
priv ate v oid appendData(StringBuilder buf, String key , String v alue) {
buf.append(", ");
buf.append(key );
buf.append('= ');
buf.append(v alue);
}
}
Reply

akhil.android Septem ber 2 3 , 2 01 1 at 1 :1 6 AM


can u please tell us how to run this code in sdk at our desktop please?
Reply

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

2/6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


CrowdFinch Nov em ber 2 5, 2 01 1 at 1 :2 0 AM
wonder & great . I really thankful to y ou
Reply

SurenSaluka Decem ber 1 2 , 2 01 1 at 1 0:2 8 PM


uses-perm ission has a printing m istake. it should be like this:
Reply

dungcrx Decem ber 2 8, 2 01 1 at 1 1 :58 PM


help m e!
i want hide display when m y phone reciev er incom ing call.how to do it ? please.
ev ery body
Reply

divy a123 January 5, 2 01 2 at 6 :03 AM


i want detail code to block sm s using the key word giv en in textbox and to block sm s from selected num ber in
contact list...any body help plz..
Reply

dungcrx February 5, 2 01 2 at 1 1 :3 5 PM
hi ev ery body
i am working m y project.When hav e an incom ing phone call, the screen has not changed its.How to do it (can
som ebody giv e m e a little code for this problem ) ? please help m e!
Reply

vinodhkumarsampat h March 2 5, 2 01 2 at 2 :55 AM


Appication force quits as i run
v inodhkum arsam path@gm ail.com
Reply

The Best April 4 , 2 01 2 at 4 :1 3 AM


It's work perfectly
Thank y ou for sharing ;)
Android The Best!
Reply

Sat y ajeet August 1 4 , 2 01 2 at 9 :57 PM


please tell m e code to read data from m m ssm s.db
Reply

umar Septem ber 2 7 , 2 01 2 at 9 :1 7 AM


i need som e help
i am m aking a projrect in which i receiv ed the GPS coordinates througth sm s into the google andriod phone .
m y problem is i want to put the the coordinates from inbox of the andriod phone in to the google m ap through som e
application.
Means the app should continuously get the coordinates from inbox and insert the coordinates for real tim e tracking
plzzzzzz plzzzzzzzzzz plzzzzzzzzzzz any one help m e out
Reply

umar Septem ber 2 7 , 2 01 2 at 9 :4 8 AM


i need som e help
i am m aking a projrect in which i receiv ed the GPS coordinates througth sm s into the google andriod phone .
m y problem is i want to put the the coordinates from inbox of the andriod phone in to the google m ap through som e
application.
Means the app should continuously get the coordinates from inbox and insert the coordinates for real tim e tracking
plzzzzzz plzzzzzzzzzz plzzzzzzzzzzz any one help m e out
plz m ail m e at
Em ail: om ar3 2 2 84 2 2 552 @gm ail.com
Reply

Harsha Nov em ber 1 , 2 01 2 at 1 2 :4 7 AM


Hi i need som e help .
In m y application when i get new inbox m essage with content please call/help autom atically read the incom ing

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

3/6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


m essage phone num ber and show an alert with m essage content for ready to coll to that num ber or not.please help
me
Reply

kevin kansagra January 1 0, 2 01 3 at 7 :2 7 PM


please tell m e how can I run this code in android sdk...?
Reply

shubham singh February 5, 2 01 3 at 2 :00 AM


Nice Thread Tutorial, i am new in android , its help m e a lot ...
I hav e got som e good links
here at androidexam ple.com
Incom m ing SMS Broadcast Receiv er
Reply

Harshal kadam March 1 2 , 2 01 3 at 3 :01 PM


i am working on robotic,few dificulties i hav e found in by robot, it is working on android app,please help m e in
dev eloping application for "sm s reading and sending "
Reply

Sulman Baig August 1 7 , 2 01 3 at 6 :55 AM


y our code is a gr8 gr8 gr8 help for m e... i need little m ore help that if i want tim e stam p of each m sg receiv ed how
i can attain that????
Reply

Sury a Septem ber 4 , 2 01 3 at 1 1 :1 3 PM


I am getting below error can u plz help m e how can i reslov e this below error
jav a.lang.Security Exception:
Neither
android.perm ission.MODIFY_PHONE_STATE.

user

1 004 5

nor

current

process

has

Reply

vishal jagdale Septem ber 2 7 , 2 01 3 at 4 :3 5 AM


it shows error "android.database.Cursor
Note: This elem ent has no attached Jav adoc and the Jav adoc could not be found in the attached source." how to fix
it
Reply

sharmila sri October 2 3 , 2 01 3 at 4 :3 0 AM


Nice tutorial :)
Reply

Mouni Bansal Decem ber 2 1 , 2 01 3 at 2 :2 8 AM


this code is not working for htc phone...
Reply

Unknown February 4 , 2 01 4 at 1 0:59 AM


Hello All,
I want to m ake a project in android like reading the m essage from the inbox and display full m essage into once it is
clicked on particular m essage. I hav e used the listv iew to display the m essage but it is display the entire content on
listv iew but i want it to display the full m sg one it is clicked on particular m sg not all at the sam e tim e.Like how
we are using the m obile inbox m sg to read the m sg. Please do help if y ou know.
Thank y ou..
Aarav
Reply

hit esh chikani March 3 , 2 01 4 at 3 :3 3 AM


can any one giv e m e a code for the restore sm s backup...???
thanx in adv ance
Reply

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

4/6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


Robert Greso March 1 2 , 2 01 4 at 3 :09 AM
Hi,
I want to get body of SMS when I click on one. I hav e tried an approach sim m ilar to contact picker. Here is m y code
:
public class Decry pt extends Fragm ent {
Button loadButton;
EditText sm sDisplay ;
public View onCreateView(Lay outInflater inflater, ViewGroup container, Bundle sav edInstanceState){
View v = inflater.inflate(R.lay out.decry pt, null);
// Button loadButton= (Button)v .findViewBy Id(R.id.)
loadButton= (Button)v .findViewBy Id(R.id.buttonLoad);
sm sDisplay = (EditText)v .findViewBy Id(R.id.editTextLoad);
loadButton.setOnClickListener(new OnClickListener() {
@Ov erride
public v oid onClick(View v ) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sm s:"));
//sendIntent.setTy pe(Sm )
//sendIntent.putExtra("sm s_body ","");
startActiv ity ForResult(sendIntent,2 );
}
});

return v ;
}
public v oid onActiv ity Result(int requestCode, int resultCode, Intent data) {
try {
// if (resultCode = = Activ ity .RESULT_OK) {
Uri ur = data.getData();
Cursor c = getActiv ity ().getContentResolv er().query (ur, null, null,
null, null);
if (c.m ov eToFirst()) {
String s = c
.getString(c
.getColum nIndex("body "));
Sy stem .out.println(s);
Toast.m akeText(getActiv ity (), s, Toast.LENGTH_LONG).show();
sm sDisplay .setText(s);
}
}catch(Exception e){
e.printStackTrace();
}
// }
}
}
It opens a Inbox like when I open original sm s app in anroid, but when I click on one m essage it doesnt copy body of
that sm s in m y edittext. Please couul y ou look at m y code and find m istake?
Thanks a lot for y our tim e
Reply

Fiaz Hussain April 2 , 2 01 4 at 1 0:2 3 PM


Hi friends;

I want to m ake a app like whatsapp plz help . all data let say com m unication , m essaging , status
Thanks
Reply

dd39c4fe-bf1c-11e3-a7 58-000bcdca4d7 a April 8, 2 01 4 at 5:54 AM


Hi
using this code i'm getting m essages are display ing with m obile num bers instead of nam es stored for num ber's in
contact book. Can any one help m e with that ?
Reply

Appzuniverse April 1 7 , 2 01 4 at 2 :4 8 AM
Wow, finally i got good code, it was worked well, i had searching m any sites about this code, Thanks for sharing,
keep updating

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

5/6

14/07/2015

Android Sample Source Code: Android Reading Inbox SMS


Android app dev elopm ent com pany
Reply

Sat ish Ghuge April 3 0, 2 01 4 at 3 :53 AM


Thanks....
Reply

JANARDHAN SURY AVANSHI June 1 6 , 2 01 4 at 4 :3 4 AM


how to delete sm s from sim card in android
Reply

ali July 2 3 , 2 01 4 at 9 :58 AM


hello ev ery one.i hav e required source code of sim ple sm s & contacts backup for m y project.if any one hav e plz share
on h_m oham m ad_ali@y m ail.com
Reply

Akanksha Khanvilkar January 2 1 , 2 01 5 at 3 :53 AM


This comment has been removed by the author.
Reply

Akanksha Khanvilkar January 2 1 , 2 01 5 at 3 :57 AM


hi I know to send sm s from one em ulator to second in android but i want to know how to send sm s from the 2 nd
em ulator from the 1 st because as i press the "send" button the m essage is sent from 1 st to 2 nd and i can it as well
but i cant giv e reply from 2 nd to 1 st em ulator.Please help m e to do that.
Reply

Pavan Kumar June 3 0, 2 01 5 at 6 :2 3 AM


Hi,it was a nice program .but i need the logic for to read sm s from a particular num ber.please help.
Reply

Enter your comment...

Comment as:

Publish

Google Account

Preview

Newer Post

Hom e

Subscribe to: Post Com m ents ( Atom )

Powered by Blogger.

http://androidsourcecode.blogspot.in/2010/10/android-reading-inbox-sms.html

6/6

Potrebbero piacerti anche