我在BroadcastReceiver
中声明了我的mainfest.xml
,但从未调用onReceive()
方法。怎么了?我不想使用注册/取消注册方法。
活动:
Intent sentI = new Intent("SMS_SENT");
PendingIntent sentPi = PendingIntent.getBroadcast(this, 0, sentI, 0);
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(number, null, message.toString(), sentPi, null);
SmsSentReceiver:
public class SmsSentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Log.i("SmsSentReceiver", "SMS sent");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Log.i("SmsSentReceiver", "Generic failure");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Log.i("SmsSentReceiver", "No service");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Log.i("SmsSentReceiver", "Null PDU");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Log.i("SmsSentReceiver", "Radio off");
break;
}
}
}
的AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<receiver android:name="com.mateusz.simplesmsapp.broadcasts.SmsSentReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_SENT" />
</intent-filter>
</receiver>
答案 0 :(得分:3)
您已在此操作的清单中注册了Receiver:"android.provider.Telephony.SMS_SENT"
。但是,您为广播创建的意图使用此操作:"SMS_SENT"
。这些需要匹配。