Reputation: 3001
Is it possible in android to redirect sms messages from some specific numbers to an application created directory and also messages will not be shown in inbox. please help
Upvotes: 0
Views: 350
Reputation: 1015
implement a broad cast reciever for reciving msg in your application
public void onReceive(Context context, Intent intent) {
// ---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String msgString = "", senderinfo = "";
String timeStamp1;
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]);
senderinfo += msgs[i].getOriginatingAddress();
msgString += msgs[i].getMessageBody().toString();
}
// ---display the new SMS message---
Toast.makeText(context, senderinfo, Toast.LENGTH_SHORT).show();
}
if(senderinfo == "Your Specific phone Numbers"){
SharedPreferences settingsActivity = getSharedPreferences("Message", Activity.MODE_PRIVATE);
SharedPreferences.Editor prefEditor = settingsActivity.edit();
prefEditor.putString(Messages, msg);
prefEditor.commit();
abortBroadcast();
}
And the retrieve the data in the application
SharedPreferences settingsActivity = getSharedPreferences("Message", Activity.MODE_PRIVATE);
settingsActivity.getString("Messages",msg);
After getting the messages clear the shared preference so that new msg can be stored
SharedPreferences.Editor editor = settingsActivity.edit();
editor.remove("Messages");
editor.clear();
editor.commit();
Upvotes: 1