Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. qt 6.8 EmailSender + activity() is not public in QtNative + cannot be accessed from outside package
Forum Updated to NodeBB v4.3 + New Features

qt 6.8 EmailSender + activity() is not public in QtNative + cannot be accessed from outside package

Scheduled Pinned Locked Moved Unsolved Qt 6
7 Posts 3 Posters 722 Views 1 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.
  • P Offline
    P Offline
    Parvathy2020
    wrote on 11 Nov 2024, 04:42 last edited by Parvathy2020 11 Nov 2024, 04:45
    #1

    Hi,

    I am trying to update my qt version from 6.5.3 -> 6.8.0 LTS.

    When I try to build my Qt application with android (android_arm64_v8a), i get the below error:

    *> Task :compileDebugJavaWithJavac FAILED
    ......\EmailSender.java:43: error: activity() is not public in QtNative; cannot be accessed from outside package
    Intent intent = ShareCompat.IntentBuilder.from(QtNative.activity()).getIntent();
    ^
    ......\EmailSender.java:58: error: activity() is not public in QtNative; cannot be accessed from outside package
    Uri contentUri = FileProvider.getUriForFile(QtNative.activity(), authority, contentFile);
    ^
    2 errors
    FAILURE: Build failed with an exception.

    • What went wrong:
      Execution failed for task ':compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.*

    Please guide with a solution ?
    Note : It is seen that similar issue is already reported by some other user. But there is no solution available
    https://forum.qt.io/topic/159350/qt-6-8-0-replacement-for-qtnative-activity?_=1731299112565

    Thanks in advance.

    J 1 Reply Last reply 11 Nov 2024, 06:23
    0
    • P Parvathy2020
      11 Nov 2024, 04:42

      Hi,

      I am trying to update my qt version from 6.5.3 -> 6.8.0 LTS.

      When I try to build my Qt application with android (android_arm64_v8a), i get the below error:

      *> Task :compileDebugJavaWithJavac FAILED
      ......\EmailSender.java:43: error: activity() is not public in QtNative; cannot be accessed from outside package
      Intent intent = ShareCompat.IntentBuilder.from(QtNative.activity()).getIntent();
      ^
      ......\EmailSender.java:58: error: activity() is not public in QtNative; cannot be accessed from outside package
      Uri contentUri = FileProvider.getUriForFile(QtNative.activity(), authority, contentFile);
      ^
      2 errors
      FAILURE: Build failed with an exception.

      • What went wrong:
        Execution failed for task ':compileDebugJavaWithJavac'.

      Compilation failed; see the compiler error output for details.*

      Please guide with a solution ?
      Note : It is seen that similar issue is already reported by some other user. But there is no solution available
      https://forum.qt.io/topic/159350/qt-6-8-0-replacement-for-qtnative-activity?_=1731299112565

      Thanks in advance.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 11 Nov 2024, 06:23 last edited by
      #2

      @Parvathy2020 What Android SDK and NDK versions do you use?

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

      P 1 Reply Last reply 11 Nov 2024, 09:16
      0
      • J jsulm
        11 Nov 2024, 06:23

        @Parvathy2020 What Android SDK and NDK versions do you use?

        P Offline
        P Offline
        Parvathy2020
        wrote on 11 Nov 2024, 09:16 last edited by Parvathy2020 11 Nov 2024, 09:58
        #3

        Hi @jsulm , This is my build configuration

        {
        "appname": "xxx_android",
        "registername": "xxx",
        "config": "release",
        "buildspec": "android-clang",
        "qtpath": "C:/Qt/6.8.0/android_arm64_v8a",
        "qmakepath": "C:/Qt/6.8.0/mingw_64/bin",
        "makepath": "C:/Qt/Tools/mingw1120_64/bin",
        "clangpath": "C:Qt/Tools/QtCreator/bin/clang/bin",
        "cmakepath": "C:/Qt/Tools/CMake_64/bin",
        "ninjapath": "C:/Qt/Tools/Ninja",
        "generator": "Ninja",
        "makecmd": "ninja",
        "java_home": "C:/android/jdk-17.0.13+11",
        "android_abi": "arm64-v8a",
        "android_home": "C:/android/android_sdk",
        "android_sdk_root": "C:/android/android_sdk",
        "android_ndk_root": "C:/android/android-ndk-r26",
        "android_ndk_host": "windows-x86_64",
        "android_ndk_platform": "26",
        "android_ndk_toolchain": "C:/android/android-ndk-r26/build/cmake/android.toolchain.cmake",
        "android_ndk_toolchain_prefix": "arm-linux-androideabi",
        "android_ndk_toolchain_version": "4.9",
        "android_ndk_tools_prefix": "arm-linux-androideabi"
        }

        f81b5526-6ee5-458e-8e97-0e7f534fbae1-image.png

        Hi @jsulm Is there any change required in sdk or ndk version for resolving the issue ? Can you please support.

        J 1 Reply Last reply 11 Nov 2024, 10:32
        0
        • P Parvathy2020
          11 Nov 2024, 09:16

          Hi @jsulm , This is my build configuration

          {
          "appname": "xxx_android",
          "registername": "xxx",
          "config": "release",
          "buildspec": "android-clang",
          "qtpath": "C:/Qt/6.8.0/android_arm64_v8a",
          "qmakepath": "C:/Qt/6.8.0/mingw_64/bin",
          "makepath": "C:/Qt/Tools/mingw1120_64/bin",
          "clangpath": "C:Qt/Tools/QtCreator/bin/clang/bin",
          "cmakepath": "C:/Qt/Tools/CMake_64/bin",
          "ninjapath": "C:/Qt/Tools/Ninja",
          "generator": "Ninja",
          "makecmd": "ninja",
          "java_home": "C:/android/jdk-17.0.13+11",
          "android_abi": "arm64-v8a",
          "android_home": "C:/android/android_sdk",
          "android_sdk_root": "C:/android/android_sdk",
          "android_ndk_root": "C:/android/android-ndk-r26",
          "android_ndk_host": "windows-x86_64",
          "android_ndk_platform": "26",
          "android_ndk_toolchain": "C:/android/android-ndk-r26/build/cmake/android.toolchain.cmake",
          "android_ndk_toolchain_prefix": "arm-linux-androideabi",
          "android_ndk_toolchain_version": "4.9",
          "android_ndk_tools_prefix": "arm-linux-androideabi"
          }

          f81b5526-6ee5-458e-8e97-0e7f534fbae1-image.png

          Hi @jsulm Is there any change required in sdk or ndk version for resolving the issue ? Can you please support.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 11 Nov 2024, 10:32 last edited by
          #4

          @Parvathy2020 Compare your dependencies with https://doc.qt.io/qt-6.5/android.html

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

          P 1 Reply Last reply 12 Nov 2024, 06:26
          0
          • J jsulm
            11 Nov 2024, 10:32

            @Parvathy2020 Compare your dependencies with https://doc.qt.io/qt-6.5/android.html

            P Offline
            P Offline
            Parvathy2020
            wrote on 12 Nov 2024, 06:26 last edited by
            #5

            Hi @jsulm , Dependencies are updated as per https://doc.qt.io/qt-6/android.html
            But still I am getting the same error.

            Not able to identify what is the root cause of the issue. package v4.x.x;

            Please find the source code ,

            import org.qtproject.qt.android.QtNative;
            import org.qtproject.qt.android.bindings.QtActivity;

            import android.content.Context;
            import android.content.Intent;
            import android.net.Uri;
            import android.os.Environment;

            import android.util.Log;

            import androidx.core.content.FileProvider;
            import androidx.core.app.ShareCompat;

            import java.io.File;
            import java.nio.file.Path;

            public class EmailSender extends org.qtproject.qt.android.bindings.QtActivity
            {
            private static final String TAG = "xxx EmailSender";

            private static EmailSender m_instance;
            
            public EmailSender()
            {
                m_instance = this;
            }
            
            ///
            /// Function to create send mail intent.
            ///   it in an email client.
            /// \param context        application context
            /// \param recipient      mail recipient email address
            /// \param subject        the subject of the email
            /// \param body           email text
            /// \param attachmentPath path to an attachment file.
            public static Intent sendMailIntent(Context context, String recipient, String subject, String body, String attachmentPathString, String chooseEmailMEssage)
            {
                Log.d(TAG, "sendEmailIntent - begin");
            
                String[] recipients = { recipient };
            
                Intent intent = ShareCompat.IntentBuilder.from(QtNative.activity()).getIntent();
                intent.setAction(Intent.ACTION_SEND);
            
                intent.setData(Uri.parse("mailto:"));
                intent.putExtra(Intent.EXTRA_EMAIL, recipients);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_TEXT, body);
            
                String authority = context.getPackageName() + ".fileprovider";
            
                if (attachmentPathString.length() > 0)
                {  
                    File contentFile = new File(attachmentPathString);
                    try
                    {
                        Uri contentUri = FileProvider.getUriForFile(QtNative.activity(), authority, contentFile);
                        intent.setType("application/gzip");
                        intent.putExtra(Intent.EXTRA_STREAM, contentUri);
                        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    }
                    catch (IllegalArgumentException e)
                    {
                        Log.w(TAG, "sendEmailIntent - unable to share: " + attachmentPathString);
                        Log.w(TAG, "sendEmailIntent                  : " + e.getMessage());
                    }
            
                }
            
                intent.setType("message/rfc822");
            
                Intent.createChooser(intent, chooseEmailMEssage);
            
                Log.d(TAG, "sendEmailIntent - end");
            
                return intent;
            }
            

            }

            J.HilkJ 1 Reply Last reply 12 Nov 2024, 06:33
            0
            • P Parvathy2020
              12 Nov 2024, 06:26

              Hi @jsulm , Dependencies are updated as per https://doc.qt.io/qt-6/android.html
              But still I am getting the same error.

              Not able to identify what is the root cause of the issue. package v4.x.x;

              Please find the source code ,

              import org.qtproject.qt.android.QtNative;
              import org.qtproject.qt.android.bindings.QtActivity;

              import android.content.Context;
              import android.content.Intent;
              import android.net.Uri;
              import android.os.Environment;

              import android.util.Log;

              import androidx.core.content.FileProvider;
              import androidx.core.app.ShareCompat;

              import java.io.File;
              import java.nio.file.Path;

              public class EmailSender extends org.qtproject.qt.android.bindings.QtActivity
              {
              private static final String TAG = "xxx EmailSender";

              private static EmailSender m_instance;
              
              public EmailSender()
              {
                  m_instance = this;
              }
              
              ///
              /// Function to create send mail intent.
              ///   it in an email client.
              /// \param context        application context
              /// \param recipient      mail recipient email address
              /// \param subject        the subject of the email
              /// \param body           email text
              /// \param attachmentPath path to an attachment file.
              public static Intent sendMailIntent(Context context, String recipient, String subject, String body, String attachmentPathString, String chooseEmailMEssage)
              {
                  Log.d(TAG, "sendEmailIntent - begin");
              
                  String[] recipients = { recipient };
              
                  Intent intent = ShareCompat.IntentBuilder.from(QtNative.activity()).getIntent();
                  intent.setAction(Intent.ACTION_SEND);
              
                  intent.setData(Uri.parse("mailto:"));
                  intent.putExtra(Intent.EXTRA_EMAIL, recipients);
                  intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                  intent.putExtra(Intent.EXTRA_TEXT, body);
              
                  String authority = context.getPackageName() + ".fileprovider";
              
                  if (attachmentPathString.length() > 0)
                  {  
                      File contentFile = new File(attachmentPathString);
                      try
                      {
                          Uri contentUri = FileProvider.getUriForFile(QtNative.activity(), authority, contentFile);
                          intent.setType("application/gzip");
                          intent.putExtra(Intent.EXTRA_STREAM, contentUri);
                          intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                      }
                      catch (IllegalArgumentException e)
                      {
                          Log.w(TAG, "sendEmailIntent - unable to share: " + attachmentPathString);
                          Log.w(TAG, "sendEmailIntent                  : " + e.getMessage());
                      }
              
                  }
              
                  intent.setType("message/rfc822");
              
                  Intent.createChooser(intent, chooseEmailMEssage);
              
                  Log.d(TAG, "sendEmailIntent - end");
              
                  return intent;
              }
              

              }

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on 12 Nov 2024, 06:33 last edited by
              #6

              @Parvathy2020 said in qt 6.8 EmailSender + activity() is not public in QtNative + cannot be accessed from outside package:

              public class EmailSender extends org.qtproject.qt.android.bindings.QtActivity

              thats no longer a valid import in Qt6, QtActivity was removed, afaik.

              I was told you have to extend the base activity now a days:

              import android.app.Activity;
              import android.os.Bundle;
              
              public class EmailSender extends Activity {
              

              Not sure how accurate that is. I was in the process of transitioning to Qt6 but other projects triggered a priority interrupt and it's on hold right now. My experience is incomplete :(


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              P 1 Reply Last reply 12 Nov 2024, 12:49
              0
              • J jsulm referenced this topic on 12 Nov 2024, 06:55
              • J.HilkJ J.Hilk
                12 Nov 2024, 06:33

                @Parvathy2020 said in qt 6.8 EmailSender + activity() is not public in QtNative + cannot be accessed from outside package:

                public class EmailSender extends org.qtproject.qt.android.bindings.QtActivity

                thats no longer a valid import in Qt6, QtActivity was removed, afaik.

                I was told you have to extend the base activity now a days:

                import android.app.Activity;
                import android.os.Bundle;
                
                public class EmailSender extends Activity {
                

                Not sure how accurate that is. I was in the process of transitioning to Qt6 but other projects triggered a priority interrupt and it's on hold right now. My experience is incomplete :(

                P Offline
                P Offline
                Parvathy2020
                wrote on 12 Nov 2024, 12:49 last edited by
                #7

                Okey @J-Hilk , Tried by extending Activity, but it is not helping.

                Due to some reason not able to access the activity().

                1 Reply Last reply
                0

                1/7

                11 Nov 2024, 04:42

                • Login

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