How to verify that a URL has been successful in QML?

Asked

Viewed 64 times

1

In QML, I can run an external URL using:

Qt.openUrlExternally(url);

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

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

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

My question is: how do I check whether a URI Scheme is valid in Qt QML?

  • Couldn’t find a solution?

  • @Apparently, the problem was in the implementation of the function openUrlExternally. In the latest version of Qt they fixed it (I mean the implementation for Android). However, for some specific cases there is no way to check only with the return of the function. Hence it is better to implement in the native part of the same code.

  • You think you can get an answer even with caveats?

  • I can do, yes.

1 answer

1


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

When the function Qt.openUrlExternally(url) 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, she did not treat the possible mistakes and Qt.openUrlExternally(url) always returned true.

With the correction of the implementation the function openURL(String url) was 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;
}

Fixing the problem I was having.

Reference of QTBUG-34716.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.