在使用此代码时,我没有收到短信。有人请帮我。 我添加了清单
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
清单上的内部应用程序
<receiver android:name=".SMSReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="10">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
接收短信的接收器类
公共类SMSReceiver扩展了BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Parse the SMS.
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
// Retrieve the SMS.
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
// In case of a particular App / Service.
//if(msgs[i].getOriginatingAddress().equals("+91XXX"))
//{
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
// str += "n";
//}
}
// Display the SMS as Toast.
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}