Abdu Egal
Abdu Egal

Reputation: 130

Calling intents by http urls in android

I have currently a webview in android.
But the webview is unable to show certain urls that contain youtube/flash videos, mp3's, mp4's, 3gp's and so on....

Is it possible to check if an internal application is able to play those formats.
I.E. if the url forwards to a youtube video then it launches the youtube app (if available), or if the url forwards to an mp3 video then it forwards to the music player.

The url that will be processed is send from an external json, so it is variabel.

Furthermore if the url is just a simple webpage (no application except the webbrowser can process it) then it should be shown in the webview.

I have browsed arround and I came up with this start:

String url = "url here for example youtube.com/watch?v=.....";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

I was not able to test this part above, but the thing missing in this snipet is, that if the url is just a simple webpage, then I dont want the webbrowser to start, but I just want it to be shown in my simple webview.

Thanks in advance,

Upvotes: 0

Views: 227

Answers (1)

Dmytro Danylyk
Dmytro Danylyk

Reputation: 19798

You can set WebViewClient to your web view, and ovveride shouldOverrideUrlLoading method. If URL ends with .mp3 (your specific format) then start intent or override onReceivedError method and process error.

Upvotes: 1

Related Questions