Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Android file sharing

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #22649

    Theo

    I’am developing an app in which I want to share a binary file created in the app. For sharing the file I want to use the Android Sharesheet as is recommended.

    So in my .pro file I have added QT += androidextras

    I have a .java file, public class QShareUtilspackage org.mnc.utils; , with the static method

        public static void sendFile(String filePath) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
    
            // We only share / send .fit files
            sendIntent.setType("application/octet-stream");
            
            Uri uriToFile = Uri.fromFile(new File(filePath));
            sendIntent.putExtra(Intent.EXTRA_STREAM, uriToFile);
    
            sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            sendIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            
            Intent shareIntent = Intent.createChooser(sendIntent, "Share .fit file");
            Activity activity = new Activity();
            activity.startActivity(shareIntent);
        }
    

    and in my .cpp file I call this method

    void AndroidShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType)
    {
        Q_UNUSED(title)
        Q_UNUSED(mimeType)
    
        QAndroidJniObject jsText = QAndroidJniObject::fromString(filePath);
        QAndroidJniObject::callStaticMethod<void>("utils/QShareUtils",
                                                      "sendFile",
                                                      "(Ljava/lang/String;)V",
                                                      jsText.object<jstring>());
    
    }
    

    I get no compile errors and can install the app on my phone. I can check that the function is called but obviously nothing happens.

    Remarkeble is that in the .cpp source I get the warning: warning instantiation of function ‘QAndroidJniObject::callStaticMethod<void>’ required here, but no definition is available

    I do not know why this is showing up although this probably needs attention.

    I’am developing on W10 Qt Creator 4.10.2 and use kit Android for arm64-v8a(Clang Qt 5.13.2 …)

    I searched for hours but have no clou as what to try next. If anyone has any ideas I would appreciate your suggestion(s).

     

Viewing 1 post (of 1 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded