Anda di halaman 1dari 3

14/07/2015

how to read SMS from specific number and delete from inbox programmatically - coderjunk.com

HOME

how to read SMS from specific number and delete from


inbox programmatically
I used this code which gets SMS messages from a specific phone number and then opens my application.
It works fine but it does not delete SMS from the inbox after getting the SMS from the specific phone number.
I'm using a simulator for testing please help tell me what is the error in the code? How can i delete SMS from
specific number???
public class SmsReceiver extends BroadcastReceiver {
String specificPhoneNumber = "15555215554";
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in--Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";

Recent Posts
How to read SQL database specific row text from
another row value
How to add build number and date from github in ruby
code?
How to hide specific lines of css from IE 7 and IE 8
How do I transfer effectively huge number of files from
my python clients to server and back?
I need to send sms to a specific number and check its
reply -Android
How do I get the line number and path of a method from a
pdb using .Net?
Searching from a site for a specific number and opening
it in an iFrame
How to join a number of fields from one table and
compare the result with another field from another table?
How to get records in a database where field (sms_text)
is equal to a specific number and display it into the
datagrid
How to read filenames in a folder and access them in an
alphabetical and increasing number order?
How to read SMS from a GSM phone ,That is already
connected to the system Using Serial port in VB.NET
How to randomly play a specific number of audio files
from a directory?

if (bundle != null)
{
//---retrieve the SMS message received--Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
String phNum = msgs[i].getOriginatingAddress();
str += msgs[i].getMessageBody().toString();
if (specificPhoneNumber.equals(phNum))
{
Uri uri = Uri.parse("content://sms/inbox");
ContentResolver contentResolver = context.getContentResolver();
String where = "address="+phNum;
Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, wh
ere, null,
null);
while (cursor.moveToNext()) {
long thread_id = cursor.getLong(1);
where = "thread_id="+thread_id;
Uri thread = Uri.parse("content://sms/inbox");
context.getContentResolver().delete(thread, where, null);
}
Intent l = new Intent(context,AgAppMenu.class);
l.putExtra("msg",str);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(l);
}
}
}
}
}

Answers
Just don't let messages from specific number to pass to the inbox. To achieve this do the following things:
1. Set a high priority for your SmsReceiver

http://www.coderjunk.com/0zxgqeUWVU/how-to-read-sms-from-specific-number-and-delete-from-inbox-programmatically.html

1/3

14/07/2015

how to read SMS from specific number and delete from inbox programmatically - coderjunk.com

<receiver android:name="SmsReceiver">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
2. Use abortBroadcast() to prevent specific message from passing to the inbox.

You can try the following changes Uri uri = Uri.parse("content://sms/inbox");

For querying String where = "address="+phNum;


Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, where, null,
null);

Thread id will be the second element long thread_id = cursor.getLong(1);


where = "thread_id="+thread_id;
Uri thread = Uri.parse("content://sms/inbox");
context.getContentResolver().delete(thread, where, null);

Similar Questions
how to add object at specific index and also remove another object from NSMutableArray?
hello friends im new in ios development i want to add object at specified index for that i code here arrnotificationtime
nsmutablearray arraywithcapacityarrnotificationviewcount for int i0 iltarrnotificationviewcount i arrnotificationtim...

How to read sms of some specific numbers in android


how can i read sms of some specific number more than 1 number from inbox please help give something idea about itor any
reference i have tried a code but not work ...

How to strip specific characters and words from String [closed]


im trying to strip a list of specified characters and words from various string variants here are the possible strings integer from 0
100 quantitycsizecon quantitycsizeconc quantitycsizeconb quantitysize quantitysizechain depending on...

How to read data in each row and each column from sql table in asp.net using C#?
sql database is studentinfo and table name is registration idnameemailphoneno 1munasunghe amilamunasingheyahoocom
0717069425 2liyanarachchihareshliya6gmailcom0756706352 protected void pageloadobject sender ev...

search array for specific number and count how many times it appears
i have an array of ages from 0100 you keep entering the ages until sentinel data99 is entered i need to then count how many
times each age appears example output the number of people 5 years old is 3 the number of people 8 years old is 1 th...

How to read in a specific line from an input file in C?


if i want to read in a specific line without knowing what exactly is in that line how would i do that using fscanf one n two n three n i
want this line number four n five n six n how would i read in the 5th line in that input text file do ...

How to get specific number of posts from a particular post-type with pagination in wordpress
i have created a posttype grammer and taxonomy named subject there are almost 220 posts in grammer now i wish to retrieve
only 25 posts from posttype grammer where taxonomy gt subject and its slug value is level1beginner these results shou...

How to push job in specific queue and limit number workers with sidekiq?
i know we can do sidekiqoptions queue foo but in this case its the worker which is assigned to only one queue foo i need to
assign a job and not a worker in specific queue with resque its easy resqueenqueuetoqueuename myjob further fo...

How do I take an unknown number of elements from a session array in php and use them as separate variables
in JavaScript?
i a webpage written in phphtml that adds the contents of a text box to a session array each time a submit button is pressed what i
need to be able to do is take the unknown number of elements in the session array and have access to each of th...

How to get a date from day number and year?


im trying to convert a day number for a given year back into its date ie the inverse of the method yday for example given the 200th
day of the year 2012 i want to get the date 20120718 ...

http://www.coderjunk.com/0zxgqeUWVU/how-to-read-sms-from-specific-number-and-delete-from-inbox-programmatically.html

2/3

14/07/2015

how to read SMS from specific number and delete from inbox programmatically - coderjunk.com

How to fetch specific number of lines from webpage using cURL (C/C++)
i am a newbie in curl and trying to implement some application which could allow user to fetch specific data from an html page
dynamic and save it to txt application is cc based and so far i am able to fetch the whole contant of html page t...

How to replace specific number of character from given string by sql query?
like s1 ldoeddldkeofkfokdkf output like ldoedkdldkeofkfokkdkf replace first and third from string with character k ...

How would I read in the city name and coordinates from this text file?
im trying to make a program that calculates the distance between two points on the earth as well as the azimuth then once i get
the distance and azimuth ill have to create a graph data structure that will use dijkstras algorithm to find the s...

how can i get a specific number(for example an stock price) from a web page [closed]
i want to get stock price from this site httpentsetmccom there is a page that tell us all price in this stocks
httpentsetmccomloaderaspxpartree121c1111 i tried to get this page content by this code address
httpentsetmccomloaderaspxpartree12...

How to get data from last number and still before space in javascript using regular expression
this is my problem below var id 10101building and construction 21 basically i have got ids data from other calculation i want to
separate to 21 here result will be 21 how can i remove ids value without 21 please any help ...

How to evenly delete a specific number of rows from a list?


i want to write the logic to delete a specific number of rows from a list and i want to select the rows for deletion as evenly as
possible this is easy when i want to delete 25 or 50 from a list i simply write the logic to delete every 4th or...

How to Get date from week number and year


i want to get date from week number and year i got week number and year from server i am trying following code but it wont work
nsdateformatter dateformatter2 nsdateformatter alloc init this is imporant we set our input date format to ma...

How to make sequence from specific number?


how to make sequence from the beginning of square number and then adding it to the previous result 7 gt 49 56 63 def
makesequencenumber lambda numbernumber end num makesequence7 numcall gt 49 numcall gt 56 ...

C: how to read in a variable amount of info from files and store it in array
i am not used to programming in c so i am wondering how to have an array and then read a variable amount of variables in a file
and those these files in the array how do i declare an array whose sizes varies do char buffer1000 fscanf...

No spam, no self-promotion, and no offensive language.

Submit Answer!

2014 coderjunk.com, All rights reserved user contributions licensed under cc by-sa 3.0 with attribution required. Any advice please contact us

http://www.coderjunk.com/0zxgqeUWVU/how-to-read-sms-from-specific-number-and-delete-from-inbox-programmatically.html

3/3

Anda mungkin juga menyukai