我写了一个接收短信收入的短信接收器,一切看起来都很好,但它不起作用,接收器没有收到短信收入。这是代码和清单内容。我记得我有同样的应用程序写得android 2.3
很好,但是这段代码正在运行,但运行android 4.x
不正常。问题是什么 ?是否取决于安全问题android 4.x
?
显现:
<receiver android:name="SmsReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
Java 代码:
public class SmsReceiver extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Logger.i("INCOMMING SMS...");
if (action == SMS_RECEIVED) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
if (messages.length > -1) {
String sendr = messages[0].getOriginatingAddress();
Logger.i(sendr);
}
}
}
}
}