跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  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?

已排程 已置頂 已鎖定 已移動 Mobile and Embedded
36 貼文 12 Posters 6.7k 瀏覽 3 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • M 離線
    M 離線
    Mikeeeeee
    寫於 最後由 Mikeeeeee 編輯
    #6

    If I add QT + = androidextras, I get an error: Unknown module (s) in QT: androidextras

    1 條回覆 最後回覆
    0
    • Shrinidhi UpadhyayaS 離線
      Shrinidhi UpadhyayaS 離線
      Shrinidhi Upadhyaya
      寫於 最後由 編輯
      #7

      Hi @Mikeeeeee , you need to add like this:-

      android: QT += androidextras
      

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      1 條回覆 最後回覆
      3
      • M 離線
        M 離線
        Mikeeeeee
        寫於 最後由 編輯
        #8

        In .pro the file was compiled. If I add #include <Qt Android Extras> I get errors: 'QtAndroidExtras' file not found , QtAndroidExtras: No such file or directory
        #include <QtAndroidExtras>

        1 條回覆 最後回覆
        0
        • SGaistS 離線
          SGaistS 離線
          SGaist
          Lifetime Qt Champion
          寫於 最後由 編輯
          #9

          Might be a silly question but are you building that with your Qt Android kit ?

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

          1 條回覆 最後回覆
          0
          • M 離線
            M 離線
            Mikeeeeee
            寫於 最後由 編輯
            #10

            MinGW does not compile, Clang compiles. Thanks.

            1 條回覆 最後回覆
            0
            • SGaistS 離線
              SGaistS 離線
              SGaist
              Lifetime Qt Champion
              寫於 最後由 編輯
              #11

              That has nothing to do with your error. You were using a Qt build that was not for Android, likely your desktop build.

              MinGW is unrelated to the Qt Android version. The compiler is provided by the Android NDK.

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

              1 條回覆 最後回覆
              2
              • M 離線
                M 離線
                Mikeeeeee
                寫於 最後由 編輯
                #12

                How to call a method in Qt from java SmsManager::createAppSpecificSmsTokenWithPackageinfo(String prefixes, PendingIntent intent)

                jsulmJ 1 條回覆 最後回覆
                0
                • M Mikeeeeee

                  How to call a method in Qt from java SmsManager::createAppSpecificSmsTokenWithPackageinfo(String prefixes, PendingIntent intent)

                  jsulmJ 離線
                  jsulmJ 離線
                  jsulm
                  Lifetime Qt Champion
                  寫於 最後由 編輯
                  #13

                  @Mikeeeeee Take a look at https://doc.qt.io/qt-5/qandroidjniobject.html

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 條回覆 最後回覆
                  1
                  • M 離線
                    M 離線
                    Mikeeeeee
                    寫於 最後由 編輯
                    #14

                    Will this option work, or should we do it differently?

                        QAndroidJniObject testSms;
                        testSms.callMethod< jint > ("createAppSpecificSmsTokenWithPackageInfo(32133)");
                    
                    Pablo J. RoginaP JonBJ 2 條回覆 最後回覆
                    0
                    • M Mikeeeeee

                      Will this option work, or should we do it differently?

                          QAndroidJniObject testSms;
                          testSms.callMethod< jint > ("createAppSpecificSmsTokenWithPackageInfo(32133)");
                      
                      Pablo J. RoginaP 離線
                      Pablo J. RoginaP 離線
                      Pablo J. Rogina
                      寫於 最後由 編輯
                      #15

                      @Mikeeeeee said in How to send SMS in android?:

                      Will this option work

                      Have you already tried? Trial and error is a way to learn...

                      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 條回覆 最後回覆
                      2
                      • M 離線
                        M 離線
                        Mikeeeeee
                        寫於 最後由 編輯
                        #16

                        It doesn't work. How can this be fixed to work?

                        1 條回覆 最後回覆
                        0
                        • M Mikeeeeee

                          Will this option work, or should we do it differently?

                              QAndroidJniObject testSms;
                              testSms.callMethod< jint > ("createAppSpecificSmsTokenWithPackageInfo(32133)");
                          
                          JonBJ 線上
                          JonBJ 線上
                          JonB
                          寫於 最後由 JonB 編輯
                          #17

                          @Mikeeeeee

                              QAndroidJniObject testSms;
                              testSms.callMethod< jint > ("createAppSpecificSmsTokenWithPackageInfo(32133)");
                          

                          With the warning that I know absolutely nothing about this:

                          You are using the overload https://doc.qt.io/qt-5/qandroidjniobject.html#callMethod, callMethod(const char *methodName). It may well be that methodName has to be a method name, "createAppSpecificSmsTokenWithPackageInfo(32133)" is a full function call. You may have to use overload https://doc.qt.io/qt-5/qandroidjniobject.html#callMethod-1, callMethod(const char *methodName, const char *sig, ...), and specify the function signature and pass 32133 as parameter, in order to call functions with parameters?

                          Have you/can you test if you can call a method which does not take any parameters, does that work OK?

                          1 條回覆 最後回覆
                          2
                          • M 離線
                            M 離線
                            Mikeeeeee
                            寫於 最後由 編輯
                            #18

                            The SmsManager class has a getcarrierconfigvalues() function without an argument.
                            This code also generates an error:

                                QAndroidJniObject testSms;
                                testSms.callMethod< jint > ("getCarrierConfigValues()");
                            
                            jsulmJ JonBJ 2 條回覆 最後回覆
                            0
                            • M Mikeeeeee

                              The SmsManager class has a getcarrierconfigvalues() function without an argument.
                              This code also generates an error:

                                  QAndroidJniObject testSms;
                                  testSms.callMethod< jint > ("getCarrierConfigValues()");
                              
                              jsulmJ 離線
                              jsulmJ 離線
                              jsulm
                              Lifetime Qt Champion
                              寫於 最後由 編輯
                              #19

                              @Mikeeeeee said in How to send SMS in android?:

                              generates an error

                              Please post the error

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 條回覆 最後回覆
                              1
                              • M 離線
                                M 離線
                                Mikeeeeee
                                寫於 最後由 編輯
                                #20

                                "org.qt project.example.smsTest" crashed.

                                jsulmJ KroMignonK 2 條回覆 最後回覆
                                0
                                • M Mikeeeeee

                                  "org.qt project.example.smsTest" crashed.

                                  jsulmJ 離線
                                  jsulmJ 離線
                                  jsulm
                                  Lifetime Qt Champion
                                  寫於 最後由 編輯
                                  #21

                                  @Mikeeeeee Does it crash when

                                  testSms.callMethod< jint > ("getCarrierConfigValues()");
                                  

                                  is executed?
                                  Also consider that some APIs require your app to request access rights from the user.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 條回覆 最後回覆
                                  1
                                  • M Mikeeeeee

                                    "org.qt project.example.smsTest" crashed.

                                    KroMignonK 離線
                                    KroMignonK 離線
                                    KroMignon
                                    寫於 最後由 編輯
                                    #22

                                    @Mikeeeeee If you remove all the "SMS sending" stuff from your source code, does it compile and can you start it on your device (or emulator) ?

                                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                    1 條回覆 最後回覆
                                    0
                                    • KroMignonK 離線
                                      KroMignonK 離線
                                      KroMignon
                                      寫於 最後由 KroMignon 編輯
                                      #23

                                      @Mikeeeeee When you have a working Qt Android App, adding SMS sending support is not that compilcated.

                                      1. ensure Android Extras are enabled (in pro file, add android: QT += androidextras)
                                      2. ensure you have add required permission in AndroidManifest.xml (android.permission.SEND_SMS )
                                      3. Add following code to the class you want to use to send SMS, for example JniHandler:
                                      #include <QtAndroid>
                                      #include <QAndroidJniObject>
                                      #include <QtAndroidExtras/QAndroidJniObject>
                                      #include <QtAndroidExtras/QAndroidJniEnvironment>
                                      #include <jni.h>
                                      ...
                                      
                                      void JniHandler::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...";
                                              }
                                          }
                                      }
                                      

                                      This should do the job.

                                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                      1 條回覆 最後回覆
                                      4
                                      • M 離線
                                        M 離線
                                        Mikeeeeee
                                        寫於 最後由 編輯
                                        #24

                                        @KroMignon said in How to send SMS in android?:

                                        android.permission.SEND_SMS

                                        android.permission.SEND_SMS must be added to .pro file?

                                        KroMignonK 1 條回覆 最後回覆
                                        0
                                        • M Mikeeeeee

                                          @KroMignon said in How to send SMS in android?:

                                          android.permission.SEND_SMS

                                          android.permission.SEND_SMS must be added to .pro file?

                                          KroMignonK 離線
                                          KroMignonK 離線
                                          KroMignon
                                          寫於 最後由 編輯
                                          #25

                                          @Mikeeeeee said in How to send SMS in android?:

                                          android.permission.SEND_SMS must be added to .pro file?

                                          No, it must be added into the manifest (AndroidManifest.xml) ==> editing-manifest-files

                                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                          1 條回覆 最後回覆
                                          2

                                          • 登入

                                          • Login or register to search.
                                          • 第一個貼文
                                            最後的貼文
                                          0
                                          • 版面
                                          • 最新
                                          • 標籤
                                          • 熱門
                                          • 使用者
                                          • 群組
                                          • 搜尋
                                          • Get Qt Extensions
                                          • Unsolved