i m about to make youtube video downloader app but don't get to integrate youtube video list so below is testing code to get started with
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://www.youtube.com");
above code simply load youtube site to a webview .. now i want to get id or link of clicked video
or
is there any other way to do so?
Read link from webview loading and parse the link
webView.setWebViewClient(new WebViewClient()
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//Parse Link
}
#Override
public void onPageFinished(WebView view, String url) {
//Parse Link
super.onPageFinished(view, url);
}
#Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Parse Link
return super.shouldOverrideUrlLoading(view, url);
}
});
Related
I m trying to load one of my cloud URL from android webview but it returns HTTP Status 401 always. If i tried from Chrome mobile browser its working as expected. Even in iOS WebView its working fine.
Here is my code, Please someone help me.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xoi);
base_url = "https://vision.xoeye.io/partners/abcd/share?";
String params = "shareId=12345678910111213141516" +
"&serviceTicket=123-123&" +
"customer=Manikanta&" +
"location=3201 S. State St. Chicago IL 60616";
webView = findViewById(R.id.webView);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setDomStorageEnabled(true);
webView.clearHistory();
webView.clearCache(false);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.clearFormData();
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return false;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
webView.loadUrl(base_url);
}
Try This
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xoi);
base_url = base_url+params;
webView = findViewById(R.id.webView);
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.setWebViewClient(new HelloWebViewClient());
//add here additional setting which you want
webView.loadUrl(base_url);
}
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
}
Hope this will help you.
I have users that receive a link to my website via email.(EG. example.com/special folder/file) When they click on the link it prompts them to open my app as it should. However I am unable to figure out how to load that link they clicked in my app. (Each user is sent a specific page tailored to them) From the research I have done all the examples are loading the website using:
String url ="http://example.com";
myview.loadUrl(url);
Again I am trying to load the orginal link they clicked on. Not the static URL.
If anyone can point me in the right direction or better yet provide a sample of how i would achieve this it would be much appreciated.
Update1
To put it simply It works like youtube. If you were sent a link via email to a youtube video it would prompt you to use the youtube app. Then load the video you were sent. All i need is my app to load the webpage the user was sent
Proper way of loading webview using ProgressDialog for user feedback.
private ProgressDialog dialog = new ProgressDialog(WebActivity.this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
String url="http://www.google.com";
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
});
dialog.setMessage("Loading..Please wait.");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
webView.loadUrl(url);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
webView = (WebView) findViewById(R.id.WebView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showProgress();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
hideProgress();
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
});
webView.loadUrl("http://google.com");
I am trying to open a link using Webview in Android. There are some links embedded into WebView. My problem is webview is not opening any link that does not starts with www. For ex, www.google.com is working but maps.google.com is not.I have also tried to override WebViewClient but it didn't work.
One thing I noticed is by putting Toast to see what url is being called in WebViewClient. It showed perfect for www.google.com but returned nothing for other links. I thing WebViewClient is not getting overriden in that case. What could be the reason. Do I have to call any ethod or some property of webview.
Any help will be appreciated.
menuView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
Toast.makeText(getApplicationContext(), "url:--" + url, Toast.LENGTH_LONG).show();
view.loadUrl(url);
return false;
}
});
Properties that I have already set are :
menuView.setVerticalScrollBarEnabled(false);
menuView.setHorizontalScrollBarEnabled(false);
final WebSettings webSettings = menuView.getSettings();
menuView.getSettings().setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setPluginState(PluginState.ON);
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
menuView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
menuView.getSettings().setBuiltInZoomControls(true);
// Below required for geolocation
menuView.getSettings().setJavaScriptEnabled(true);
menuView.getSettings().setGeolocationEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
// in oncreate
webview.setWebChromeClient(new wecrome());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadsImagesAutomatically(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview.setWebViewClient(new MyBrowser());
webview.getSettings().setPluginState(PluginState.ON);
webview.loadUrl("http://www.example.net/locations/");
//inner class
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
view.addJavascriptInterface(new Object() {
#JavascriptInterface
public void performClick() throws Exception {
Log.d("LOGIN::", "Clicked");
Toast.makeText(googleplus.this, "Login clicked",
Toast.LENGTH_LONG).show();
}
}, "login");
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
System.out.println("started");
pd.show();
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
pd.dismiss();
System.out.println("ends");
super.onPageFinished(view, url);
}
}
I have a simple webview ,nothing complex
URL = getIntent().getExtras().getString(FinalVariables.LOAD_URL);
mWebView =(WebView) findViewById(R.id.mywebview);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
if(!TextUtils.isEmpty(URL))
mWebView.loadUrl(URL);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
But for some reason if the opened page has a video in it, it won't get played
this is what I am seeing now.But when I run this same code on sony device,no problems there.I tried enabling the android:hardwareAccelerated="true" in AndroidManifest.xml but didn't work.Any help is appreciated.
I found a solution for this and was quite simple.Adding a single line on shouldOverrideUrlLoading fixed the problem ie,
mWebView.setWebChromeClient(new WebChromeClient());
Hope this will help someone.
i'm new to android programing.my problem is that in my webview when i click on any link its opening to a new web browser i dont need this i want it to be opened in my app itself.can someone help me??
this is my code
title = extras.getString("title");
url = extras.getString("url");
TextView text=(TextView) findViewById(R.id.textView1);
text.setText(title);
WebView myWebView =(WebView)findViewById(R.id.WebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
i tried this but my webview is not loading its showing a blank screen
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.google.com");
public class myWebClient extends WebViewClient
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}