gpt4 book ai didi

android - 发送未收到的短信广播

转载 作者:行者123 更新时间:2023-11-29 18:58:11 34 4
gpt4 key购买 nike

我必须发送短信并在发送后执行一些操作,我使用广播挂起 Intent 广播状态如下。

BroadcastReceiver smsStatusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
mBroadcastManager = LocalBroadcastManager.getInstance(this);
mBroadcastManager.registerReceiver(smsStatusReceiver, new IntentFilter(ACTION_SENT));
mBroadcastManager.registerReceiver(smsStatusReceiver, new IntentFilter(ACTION_DELIVERED));

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Utils.sendSMS(MainActivity.this, "123456", "test", ACTION_SENT, ACTION_DELIVERED);
}
});
}

在实用程序中

public static void sendSMS(Activity activity, String destination, String text, String sentAction, String deliveryAction) {    
PendingIntent sentPI = null;
PendingIntent deliveredPI = null;
if (!TextUtils.isEmpty(sentAction)) {
sentPI = PendingIntent.getBroadcast(activity, 0, new Intent(sentAction), 0);
}
if (!TextUtils.isEmpty(deliveryAction)) {
deliveredPI = PendingIntent.getBroadcast(activity, 500, new Intent(deliveryAction), 0);
}
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destination, null, text, sentPI, deliveredPI);
}

尽管短信已成功发送,但从未调用过 onReceive(),在文档中找不到任何不直接的内容。知道发生了什么事吗?

最佳答案

您是否在 Manifest 类中添加了 BroadcastReceiver?

<receiver android:name=".receiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

关于android - 发送未收到的短信广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49556694/

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