我正在开发一个小型的android项目。在onReceive方法中,我试图设置一个断点,但无论我做什么,断点都不会发生。 onReceive中的所有内容都运行良好,但我似乎无法理解为什么断点不会被击中。
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class NotiActivity extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// get sms objects
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus.length == 0) {
return;
}
// large message might be broken into many
SmsMessage[] messages = new SmsMessage[pdus.length];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(messages[i].getMessageBody());
}
String message = sb.toString();
String[] indstr = message.split(" ");
if (indstr[0].equals("fmcqr")) {
DatabaseHandler db = new DatabaseHandler(context);
db.addOrder(new Orders(indstr[2], indstr[3], 1));
for(int i = 0; i < indstr.length; i++)
Toast.makeText(context, indstr[i], Toast.LENGTH_SHORT).show();
// prevent any other broadcast receivers from receiving broadcast
// abortBroadcast();
}
Toast.makeText(context, indstr[0], Toast.LENGTH_SHORT).show();
}
}
}
}
这是代码,我在每一行都试过断点。
答案 0 :(得分:0)
您需要指定权限:
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
或者你可以参考 - What is the Android sent sms intent?