gpt4 book ai didi

android - 断点没有在 BroadcastReceiver 的 Receive 上被击中

转载 作者:行者123 更新时间:2023-11-29 14:14:42 25 4
gpt4 key购买 nike

我正在做一个小型的安卓项目。在 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();
}
}
}
}

这是代码,我在每一行都尝试了一个断点。

最佳答案

您需要指定权限:

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

或者您可以引用- What is the Android sent sms intent?

关于android - 断点没有在 BroadcastReceiver 的 Receive 上被击中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25334175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com