Ref: Android - how to make my app default sms app programatically
Not according to the code in your question. Let's review the four requirements from the blog post:
In a broadcast receiver, include an intent filter for
SMS_DELIVER_ACTION ("android.provider.Telephony.SMS_DELIVER"). The
broadcast receiver must also require the BROADCAST_SMS permission.
You have this, in the form of your PhoneStateReceiver.
In a broadcast receiver, include an intent filter for
WAP_PUSH_DELIVER_ACTION
("android.provider.Telephony.WAP_PUSH_DELIVER") with the MIME type
"application/vnd.wap.mms-message". The broadcast receiver must also
require the BROADCAST_WAP_PUSH permission.
You do not have this.
In your activity that delivers new messages, include an intent filter
for ACTION_SENDTO ("android.intent.action.SENDTO") with schemas, sms:,
smsto:, mms:, and mmsto:.
You have this, in the form of DashboardActivity.
In a service, include an intent filter for ACTION_RESPONSE_VIA_MESSAGE
("android.intent.action.RESPOND_VIA_MESSAGE") with schemas, sms:,
smsto:, mms:, and mmsto:. This service must also require the
SEND_RESPOND_VIA_MESSAGE permission.
You have this, in the form of HeadlessSmsSendService.
So, add a for WAP_PUSH_DELIVER_ACTION, following the
instructions, and see if that helps.
Ref: Android – Listen For Incoming SMS Messages
public class SmsListener extends BroadcastReceiver{
private SharedPreferences preferences;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
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]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
}
}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
}
}
Note: In your manifest file add the BroadcastReceiver-
<receiver android:name=".listener.SmsListener">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Add this permission:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
OR
Note that on some devices your code wont work without
android:priority="1000" in intent filter:
<receiver android:name=".listener.SmsListener">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
And here is some optimizations:
public class SmsListener extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
String messageBody = smsMessage.getMessageBody();
}
}
}
}
Note: The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0. The value must be greater than -1000 and less than 1000.
Here's a link.
For More : Android – Listen For Incoming SMS Messages