简体   繁体   中英

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.

Now that I have the Dual Sim data I want to send a message through a specific Sim card using SmsManager. 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();
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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