我正在关注某个SMS Android程序的教程,特别是SMS Parsing。
我遇到了这个特殊错误...
Public class SMSTestActivity extends BroadcastReceiver {
public void onReceive (Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
我该如何解决这个问题?
答案 0 :(得分:0)
您忘了将动作添加到班级:
static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
不要忘记将以下代码段添加到清单中:
<uses-permission id="android.permission.RECEIVE_SMS" />
<application>
<receiver class="SMSTestActivity">
<intent-filter>
<action android:value="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>