Open Soundcloud URL in Soundcloud Native Application from WebView

Scenario

I have a WebView application in an Android application that contains an embedded Soundcloud (from Embedly). This insert has two buttons: "Play Soundcloud" and "Listen in the browser."

The Play on Soundcloud button contains a URL in the format intent://tracks:257659076#Intent;scheme=soundcloud;package=com.soundcloud.android;end

The code

My WebView uses a custom WebViewClient (because I need to intercept some URLs for some other things).

protected class WebViewClient extends android.webkit.WebViewClient {
    public WebViewClient() { }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        PackageManager packageManager = context.getPackageManager();

        // Create an Intent from the URL.
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

        // Find out if I have any activities which will handle the URL.
        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);

        // If we have an app installed that can handle the URL, then use it.
        if (resolveInfoList != null && resolveInfoList.size() > 0) {
            Intent viewUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            context.startActivity(viewUrlIntent);
        }
        else {
            // Do something else.
        }
        return true;
    }
}

Problem

" " . " Soundcloud" shouldOverrideUrlLoading WebViewClient ( ). , URL- Soundcloud.

WebViewClient WebView ( ), ​​ "Play on Soundcloud" , , Soundcloud.

()

, , , URL-, , URL-, , Soundcloud ( SO). URL- "soundcloud://tracks:[TRACK_ID]" Soundcloud.

?

, ", URL", - , , , (?!) WebViewClient, WebView, ? .

+4

Source: https://habr.com/ru/post/1649152/


All Articles