gpt4 book ai didi

android - 如何在非 Activity 类中发送短信?

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

我有一个服务类和一个实用程序类。在 util 类中,我向手机发送短信。但在 util 类中,有许多函数使用参数,如上下文,但 util 没有扩展任何东西,只是一个简单的类。怎么做?

最佳答案

就像这样。将所有 pendingIntent 设置为 null。

public static boolean smsSender(String to, String msg) {
SmsManager smsManager = SmsManager.getDefault();
try {

List<String> contents = smsManager.divideMessage(msg);
for (String content : contents){
smsManager.sendTextMessage(to, null, content, null, null);
}

return true;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return false;
}
}

关于android - 如何在非 Activity 类中发送短信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116488/

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