gpt4 book ai didi

android - SmsManager 成功

转载 作者:行者123 更新时间:2023-11-30 04:41:28 27 4
gpt4 key购买 nike

我正在使用以下代码发送短信。但这似乎不会在未发送短信时产生异常。例如,当没有足够的钱发送时,我仍然会去 smsSucces();有没有人知道解决此问题的方法以确保它已发送?

    private boolean composeSms(String telefoonnr, String boodschap) {
if(telefoonnr.equals("") || boodschap.equals("")) {
smsFail();
return false;
}
try {
SmsManager sm = SmsManager.getDefault();
//PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SmsActivity.class), 0);
sm.sendTextMessage(telefoonnr, null, boodschap, null, null);
DataClass dc = (DataClass) getApplicationContext();
dc.setBoolean(DataClass.ACTIVATED_SMS, true);
dc.setString(DataClass.SMS_NUMBER, telefoonnr);
Log.d("temp","sms send succesfully");
smsSucces();
return true;
}
catch (Exception e) {
e.printStackTrace();
smsFail();
return false;
}


}

最佳答案

您好,您可以使用广播来获取短信发送报告 `

代码如下

//短信发送待定 Intent

PendingIntent deliveredIntent = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED_ACTION), 0);

//短信发送接收者

registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "SMS sent intent received.");
}
}, new IntentFilter(SENT_ACTION));

//短信发送接收者

registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "SMS delivered intent received.");
}
}, new IntentFilter(DELIVERED_ACTION));

关于android - SmsManager 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5908790/

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