gpt4 book ai didi

android - sendMultipartTextMessage ISms$Stub$Proxy.sendMultipartTextOnSubscription NullPointerException 异常

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

我得到以下代码的空指针异常:

我有超过 160 个字符长度的 SMS,所以我使用 divide() 将它们分开,然后添加一个发送的 PendingIntent。

有时会出现这个异常。我的手机号码和短信数据不为空;

   String SENT = "SMS_SENT";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
SENT), 0);

// ---when the SMS has been sent---
BroadcastReceiver sentSMSStatusReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
//TOAST
}
unregisterReceiver(this);
}
};
registerReceiver(sentSMSStatusReciever, new IntentFilter(SENT));

SmsManager smsManager = SmsManager.getDefault();

// since message is greater than 160 chars
ArrayList smsContructedList = smsManager.divideMessage("SMS Content goes here ....");

ArrayList<PendingIntent> sentPIList = new ArrayList<PendingIntent>(1);

sentPIList.add(sentPI);

smsManager.sendMultipartTextMessage("Mobile Number goes here", null,
smsContructedList, sentPIList, null);

日志:

java.lang.NullPointerException
E/AndroidRuntime( 4527): at android.os.Parcel.readException(Parcel.java:1328)
E/AndroidRuntime( 4527): at android.os.Parcel.readException(Parcel.java:1276)
E/AndroidRuntime( 4527): at com.android.internal.telephony.ISms$Stub$Proxy.sendMultipartTextOnSubscription(ISms.java:1351)
E/AndroidRuntime( 4527): at android.telephony.SmsManager.sendMultipartTextMessage(SmsManager.java:354)

最佳答案

添加这个:

ArrayList<String> messageArray = smsManager.divideMessage(myMessage);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < messageArray.size(); i++)
sentIntents.add(sentPI);
smsManager.sendMultipartTextMessage(sendTo,null,messageArray,sentIntents, null);

关于android - sendMultipartTextMessage ISms$Stub$Proxy.sendMultipartTextOnSubscription NullPointerException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9597804/

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