Video at YouTube mobile website in WebView doesn't work - Android - android

In my WebView I'm loading YouTube official website:
http://m.youtube.com/index?desktop_uri=%2F&gl=US#/
I want the user to be able to choose a video and simply watch it. The WebView doesn't do it so I thought that maybe I should run an intent to youtube app.
First, I had to export the videoID from the link.
I tried this code, but it doesn't match the link..:
public class BrowserClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Check if YouTube video link
Log.d("WBC", "loading link: " + url);
String youTubeLink = "http://m.youtube.com/index?desktop_uri=%2F&gl=US#/watch?xl=xl_blazer&v=";
if (url.startsWith(youTubeLink)){
Log.d("WBC", "This is a YouTube link: " + url);
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s", url.substring(youTubeLink.length(),url.length())))));
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
}
Any help?

Please try this code, it works in mine apps perfectly.
String sPath = "urlGoesHere";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(sPath));
startActivity(i);

Related

opening app links from a webview

I have an android app, there is an activity with a webView, it acts like a browser (it open some links I provided). Whenever I browse through my webView if there is a link that leads to play store to download an app my webView can't respond, it says 'webpage not available'. It can't send an intent to open play store or something like google chrome. How can I do it?
This works for me and opens play store app if it is installed and else shows playstore
link within the same webView.
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}
});

How to open a web browser in WebView app when an external link is clicked?

I want to open external links in web browser using intent and should not open in my WebView app except my internal links starts with "https://www.ecommerce.in/"
I have written code as given below:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (!url.contains("https://www.ecommerce.in/"))
{
Uri uri = Uri.parse(url);
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
view.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
} else {
webViewProduct.loadUrl(url);
return true;
}
}
This code is working perfectly as I want but the problem is when I pressed back button on web browser the same external link is opening in my WebView app.
Please let me know where I'm doing wrong. Thanks in advance.
You should have to remove view.loadUrl(url) from you code , So
Please replace your code as given below
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (!url.contains("https://www.ecommerce.in/"))
{
Uri uri = Uri.parse(url);
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
CookieManager.getInstance().setAcceptCookie(true);
} else {
webViewProduct.loadUrl(url);
return true;
}
}

Facebook share button in Android Application

FB share button could successfully oepn the FB messenger app in Chrome browser.
However, the same source code, it fail to open the FB messenger app if display in Android APP application, and this application display web page using Chrome browser inside.
How to fix it?
You could provide a custom WebViewClient implementation to your WebView that checks for facebook.com links (or whatever links you like) and then explicitly fire an Intent so others can pickup the Action, instead of allowing the WebView to handle it as it sees fit.
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Uri uri = Uri.parse(url);
if (uri.getHost().contains("facebook.com")) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
return false;
}
} catch(Exception e){
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}
});

Android Studio Webview open link directly on Google Play

I have a Web App that loads locally html.
In one html, I have a link to a Google Play app, but the link opens inside the app, inside the webview.
On iOS devices any link https://itunes.apple.com/app/id000 will automatically open iTunes/App Store on the devices.
Is there a way to open the Google Play app directly from an html?
I'm trying _blank or the market:// as suggested on other questions, but nothing works.
App Link
App Link 2
Thanks!
you can use this it will work
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Google Play app is not installed, you may want to open the app store link
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}});
maybe this will help any one

Cannot open skype custom URL from android WebView

I'm currently developing an application with android WebView.
However, the website has a link that will invoke Skype application.
The link work fine when try with Chrome browser on android, but it return an error when try to open in android WebView. Actually, it gave me an Webpage not Available error.
Any advice?
Regards.
You should check the url that is click/opened in the webview and check if there is an application that handles this kind of urls:
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == skype url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
} else {
view.loadUrl(url);
}
return true;
}
});

Categories

Resources