我正在从应用程序内发送短信,并且能够发送短信。问题是未调用发送/已发送的广播的挂起意图。我需要再放些什么吗?
请在此处检查我的代码:
Android清单
<uses-feature android:name="android.provider.Telephony" android:required="true"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<receiver
android:name=".receivers.SentReceiver">
<intent-filter>
<action android:name="sms.SENT" />
</intent-filter>
</receiver>
待定意向
PendingIntent.getBroadcast(this, messageId, new Intent("sms.SENT"), PendingIntent.FLAG_UPDATE_CURRENT);
发送短信
private void sendSms(Message msg, Uri smsUri, int messageId) {
SmsManager smsManager = SmsManager.getDefault();
// set up sent and delivered pending intents to be used with message request
PendingIntent sentPI = view.getSentPendingIntent(smsUri, messageId);
PendingIntent deliveredPI = view.getDeliveredPendingIntent(smsUri, messageId);
// divide the long text of sms into parts as it can be more than 160 Char
ArrayList<String> parts = smsManager.divideMessage(msg.getMsg());
// so as we need different reports for different sms
ArrayList<PendingIntent> sPI = new ArrayList<>();
ArrayList<PendingIntent> dPI = new ArrayList<>();
for (String part : parts) {
sPI.add(sentPI);
dPI.add(deliveredPI);
}
// send SMS
try {
smsManager.sendMultipartTextMessage(msg.getTitle(), null, parts, sPI, dPI);
} catch (Exception e) {
Log.e(TAG, "exception thrown", e);
}
}
接收器
public class SentReceiver extends BroadcastReceiver {
private static final String TAG = "SentReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// debug point doesn't reach here and logs are also not getting print
String path = intent.getStringExtra(Defaults.IntentKeys.MESSAGE_URI);
Log.e("reached","sent receiver");
}
}
我已经调试了它,但是它不在这里。我是否需要添加其他内容? -我的应用是默认的短信应用