Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Android - Open with/Share with popup does not appear and no app opens



  • Hi all,

    Can anyone offer any insight as to why the "Open with" or "Share with" popup doesn't appear on my phones with Android 8.X phones but it does on my Note 4 with 6.X on it?

    Here is my situation:

    I have a Qt app that generates a pdf and displays it to the user. On my Nexus 6P and my S9, it generates the pdf but does not open it in the pdf viewer. The "Open with" doesn't even come up. Also, I have a button that is supposed to email the pdf but when I touch the email button, nothing happens.

    It used to work and still does on Android 6.X. I have a 7.X phone and will test to see if it works on that and update this question but has anyone had this problem and figured it out?


  • Moderators

    @ebonnett
    now the question how do you open the intent exactly?



  • Here is the code I'm using in a .java file

    boolean sendMail(String emailSubject, String emailBody, String emailRecipient, String attachmentFilename)
    {
    try
    {
    System.out.println("sendMail...");
    String f = "file://" + attachmentFilename;

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("message/rfc822");
            intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
            intent.putExtra(Intent.EXTRA_TEXT, emailBody);
            intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailRecipient});
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
                java.io.File file = new java.io.File(attachmentFilename);
                Uri apkURI = FileProvider.getUriForFile(
                        _parentContext,
                        _parentContext.getApplicationContext()
                                .getPackageName() + ".provider", file);
    
                intent.putExtra(Intent.EXTRA_STREAM, apkURI);
            }
            else
            {
                Uri uri = Uri.parse(f);
                intent.putExtra(Intent.EXTRA_STREAM, uri);
            }
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Intent mailer = Intent.createChooser(intent, null);
            if (mailer == null)
            {
                System.out.println("sendMail no mailer... ");
                return false;
            }
    
            _parentContext.startActivity(mailer);
        }
        catch (Exception  ex)
        {
            System.out.println("sendMail exception... ");
            ex.printStackTrace();
            return false;
        }
    
        return true;
    }
    
    boolean openPdf(String filename) 
    {
        try 
        {
            Uri apkURI = null;
            java.io.File file = new java.io.File(filename);
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) 
            {
    
                apkURI = FileProvider.getUriForFile(
                        _parentContext,
                        _parentContext.getApplicationContext()
                                .getPackageName() + ".provider", file);
            } 
            else 
            {
                apkURI = Uri.fromFile(file);
            }
        
            Intent intentUrl = new Intent(Intent.ACTION_VIEW);
            intentUrl.setDataAndType(apkURI, "application/pdf");
            intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intentUrl.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            _parentContext.startActivity(intentUrl);
        } 
        catch (Exception e) 
        {
            System.out.println("pdfopen exception... ");
            e.printStackTrace();
            return false;
        }
    
        return true;
    }


  • So I figured out the problem. I had some java files in my Qt project (C++). When I changed the package name, it wreaked havoc on all kinds of things. I had my java files in a package that matched the android package name. So I changed the java package to reflect the new android package name but did not see that there were "magic" strings to load the class into the QAndroidJniObject. That was causing the APK to crash ultimately but it also caused the Open With popups to not show.


Log in to reply