当我的应用程序通过后退按钮最小化时,我想接收短信,当我通过主页按钮最小化时它收到短信,但是当按下按钮时没有收到广播消息。谢谢。
我的应用程序代码是:
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiver, filter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiver);
}
和
@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();
}
所以当我通过后退按钮最小化时如何接收短信谢谢。