Qt World Summit: Register Today!

How to send SMS in android?

  • Hi!
    How to send SMS in android?
    Tried to do so, but it does not work:

    void MainWindow::on_testButton_clicked()
        //QAndroidJniObject testSms;
        //testSms.callMethod< jint > ("getCarrierConfigValues()");
        sendSMS("+7235235", "test text");
    void MainWindow::sendSMS(const QString& phoneNumber, const QString& message)
        QtAndroid::runOnAndroidThreadSync([phoneNumber, message]  {
            // get the Qt android activity
            QAndroidJniObject activity = QtAndroid::androidActivity();
            if (activity.isValid()){
                // get the default SmsManager
                QAndroidJniObject mySmsManager = QAndroidJniObject::callStaticObjectMethod("android/telephony/SmsManager",
                                                                                           "()Landroid/telephony/SmsManager;" );
                // get phone number & text from UI and convert to Java String
                QAndroidJniObject myPhoneNumber = QAndroidJniObject::fromString(phoneNumber);
                QAndroidJniObject myTextMessage = QAndroidJniObject::fromString(message);
                QAndroidJniObject scAddress = NULL;
                QAndroidJniObject sentIntent = NULL;
                QAndroidJniObject deliveryIntent = NULL;
                // call the java function:
                // public void SmsManager.sendTextMessage(String destinationAddress,
                //                                        String scAddress, String text,
                //                                        PendingIntent sentIntent, PendingIntent deliveryIntent)
                // see: http://developer.android.com/reference/android/telephony/SmsManager.html
                                               myTextMessage.object<jstring>(), NULL, NULL );
            else {
                qDebug() << "Something wrong with Qt activity...";

  • @Mikeeeeee why are double posting? You've already started the same exact thread 3 weeks ago or so...

  • Lifetime Qt Champion

    Locking topic as duplicate.

Log in to reply