Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to send SMS in android?
Forum Updated to NodeBB v4.3 + New Features

How to send SMS in android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 451 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    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",
                                                                                           "getDefault",
                                                                                           "()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
    
                mySmsManager.callMethod<void>("sendTextMessage",
                                              "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/app/PendingIntent;Landroid/app/PendingIntent;)V",
                                               myPhoneNumber.object<jstring>(),
                                               scAddress.object<jstring>(),
                                               myTextMessage.object<jstring>(), NULL, NULL );
    
                  }
            else {
                qDebug() << "Something wrong with Qt activity...";
            }
        });
    }
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • M Mikeeeeee

      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",
                                                                                             "getDefault",
                                                                                             "()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
      
                  mySmsManager.callMethod<void>("sendTextMessage",
                                                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/app/PendingIntent;Landroid/app/PendingIntent;)V",
                                                 myPhoneNumber.object<jstring>(),
                                                 scAddress.object<jstring>(),
                                                 myTextMessage.object<jstring>(), NULL, NULL );
      
                    }
              else {
                  qDebug() << "Something wrong with Qt activity...";
              }
          });
      }
      
      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

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

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Locking topic as duplicate.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved