Is it possible in android to filter the SMS from a specific number in android.And save it in a specific database.and the SMS should not be visible in the inbox...
Asked
Active
Viewed 1,911 times
2 Answers
2
ya is it possible.
in mainfest file add following code:
<receiver android:name="com.example.Sms_BReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
after that create a class use following code
public class Sms_BReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] messageString = null;
Object[] pdus = (Object[]) bundle.get("pdus");
messageString = new SmsMessage[pdus.length];
for (i = 0; i < messageString.length; i++) {
messageString[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
Phone_no = messageString[0].getOriginatingAddress();
Message_body = messageString[0].getMessageBody();
Time = messageString[0].getTimestampMillis();
CharSequence text = str;
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
if (Phone_no.contains(here check no to filter) {
here delete message form inbox
and save in our own db
} else {
}
}
i hope this code will use full for u

K.Muthu
- 1,232
- 1
- 17
- 38
-
I don't where this code came from, it's all over the internet. How can this possibly function? Look at this line: messageString[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); You cannot convert a byte into a byte[]. Also .createFromPdu() takes a byte[] as arg NOT a byte which is what pdus[i] is. – JamisonMan111 Dec 05 '17 at 05:20
2
You have yo do this in 3 step:
- read SMS from Specific number you have to look in to this link then after
- you have to create Database for store all info about SMS(like id, body, number, time) for that check this link
- you have to Delete SMS from INBOX check this link for delete SMS.
add below permission for do all step:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

Community
- 1
- 1

Dhaval Parmar
- 18,812
- 8
- 82
- 177