I want to received sms when my application is minimized by back button,when I minimized by home button then it received sms,but when press button then not received broadcast messages. Thanks.
My app code are :
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiver, filter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiver);
}
and
@Override
public void onReceive(Context context, Intent intent) {
String address = "";
String message = "";
Bundle extras = intent.getExtras();
if (extras != null) {
Object[] smsExtra = (Object[]) extras.get("pdus");
for (int i = 0; i < smsExtra.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
message += sms.getMessageBody();
address = sms.getOriginatingAddress();
}
Toast.makeText(context, "SMS Received>>" + message +"From >>" + address,
Toast.LENGTH_LONG).show();
}
SO how can I received sms when minimized by back button thanks.
You're unregistering the broadcast receiver when the user leaves obviously its not going to work. Instead of registering at the app level, register it in the manifest. That way its not dependent on the state of the application.
To learn more: http://developer.android.com/reference/android/content/BroadcastReceiver.html