简体   繁体   English

如何在双SIM卡Android手机中使用SmsManager直接发送短信?

[英]How to send sms directly using SmsManager in dual sim android phones?

I had problems to get data about Dual Sim android phones, but it was possible through reflection of specific implementations of Telephonymanager class by each manufacturer. 我在获取有关Dual Sim android手机的数据时遇到了问题,但是可以通过每个制造商反映Telephonymanager类的特定实现来实现。

Now that I have the Dual Sim data I want to send a message through a specific Sim card using SmsManager. 现在,我具有Dual Sim数据,我想使用SmsManager通过特定的Sim卡发送消息。 However I wasn't able to do that so far. 但是到目前为止,我还无法做到这一点。 Can someone help me? 有人能帮我吗? Does anyone know an approach for doing that? 有人知道这样做的方法吗?

Just pass sender Phone Number and Sms Text you want to send to this metthod 只需将您要发送的发件人电话号码和短信发送给此方法

public void sendSMS(String phoneNo, String msg) {

    try {

        String SENT = "sent";
        String DELIVERED = "delivered";

        Intent sentIntent = new Intent(SENT);
        /* Create Pending Intents */
        PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0, sentIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        Intent deliveryIntent = new Intent(DELIVERED);

        PendingIntent deliverPI = PendingIntent.getBroadcast(mContext, 0, deliveryIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        /* Send SMS */
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, msg, sentPI, deliverPI);
    } catch (Exception ex) {

        ex.printStackTrace();
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM