How to check if a URL was successful in QML?

1

In QML, I can run an external URL using:

Qt.openUrlExternally(url);

With this, I can, for example, have the Facebook app open in a certain profile:

var test = Qt.openUrlExternally('fb://profile/###########');

However, if the Facebook app is not installed the URL will fail, but the Qt.openUrlExternally() function will continue to return true . In that case, if I can verify that the call has failed, I could open Facebook via the browser instead of the app.

My question is: how do I check if a URI scheme is valid in Qt \ QML?

    
asked by anonymous 19.05.2014 / 18:11

1 answer

1

The problem was actually an implementation error for the Android version of Qt (which was what I was using).

When the Qt.openUrlExternally(url) function was called, in the native part of the code the following function was called (in QtNative.java):

public static void openURL(String url)
{
    Uri uri = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    activity().startActivity(intent);
}

That is, it did not handle the possible errors and Qt.openUrlExternally(url) always returned true.

With the implementation fix the openURL(String url) function looks like this:

public static boolean openURL(String url)
{
    boolean ok = true;

    try {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        activity().startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
        ok = false;
    }

    return ok;
}

Correcting the problem I was having.

QTBUG-34716

Reference

    

14.10.2014 / 02:29