如何发送短信在非活动类? [英] how to send sms in a non-activity class?

查看:132
本文介绍了如何发送短信在非活动类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务类,以及UTIL类。
在UTIL类,我发送短信到手机。但在UTIL类中,有很多功能使用PARAMS如上下文,但使用util延伸没什么,只是一个简单的类。怎么办呢?

i have a service class, and a util class. in util class,i send a sms to a phone. but in util class ,there are many functions use params such as context,but the util extends nothing,just a simple class. how to do it ?

推荐答案

就这样。设置所有的PendingIntent空。

Just like this. set all 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;
    }
}

这篇关于如何发送短信在非活动类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆