Intents on QT android



  • Can we use intents on Qt for android ? I need to open a pdf file from the sd card. Once i select a file using the UI, i need to get a list of applications which can open that file( using intents).

    In short, how can we raise an intent in QT for android ?



  • Hi,

    The correct Qt way of opening a local file is using
    @QDesktopServices::openUrl((QUrl("file:///sdcard/temp/file.pdf")))@

    In Qt4 on Android (Neccessitas), I filed a bug on this some years ago:
    "https://bugs.kde.org/show_bug.cgi?id=307605":https://bugs.kde.org/show_bug.cgi?id=307605

    I don't know for sure the current status on this in Qt5, but please go ahead and file a bugreport if it's not fixed.

    My workaround for this at the moment is using Android intents like this (using JNI - java code):
    @import android.net.Uri;
    import android.provider.MediaStore;
    import android.webkit.MimeTypeMap;

    ...

    public void JIntentActionViewFile(final String data)
    {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        File file = new File(data);
        String ext=file.getName().substring(file.getName().lastIndexOf(".")+1).toLowerCase();
        String type = mime.getMimeTypeFromExtension(ext);
        intent.setDataAndType(Uri.fromFile(file),type);
        QtActivity.startActivity(intent);
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.