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");
Related
I am getting message 'Server hangup' when loading url into webView and this message is not implemented in either Android side or server side. If anyone knows how to solve this issue, Please help. Thanks
I have used following code:
private WebView mWebview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new MyWebChromeClient(this));
mWebview .loadUrl("our server url");
setContentView(mWebview);
}
private class MyWebChromeClient extends WebChromeClient {
Context context;
public MyWebChromeClient(Context context) {
super();
this.context = context;
}
}
Please check screenshot
Google.com is secure domain. You have to use https://www.google.com instead of http://www.google.com.
Please use this method and set your website url :
Example :startWebView("https://stackoverflow.com");
private void startWebView(String url) {
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Error:" + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl(url);
}
Webview shows you the HTML returned by the URL that has been loaded.
onReceivedError() will not be called if you get response containing the error message.
Check what you receive as HTML from server using the following code in onPageFinished().
webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
#Override
public void onReceiveValue(String html) {
// displays the HTML received after the URL is loaded.
Log.e("#Eval", "Html -> " + html);
}
});
As you have mentioned that the message is not implemented in your app, it must have been be received from the server end.
I am using webview for showing Flipkart website in my application.
Everything is working fine as needed except one thing:
when I click on BuyNow button, select variant view gets visible.
This view comes for 1 sec and then show the white blank page.
Is there any setting i need to enable in webview to show this types of view?
I had already gone through many questions on Stackoverflow but nothing helped me.
I tried setting webchromeclient and below methods on webview with no success.
shopping_webview.getSettings().setAllowFileAccess(true);
shopping_webview.getSettings().setAllowContentAccess(true);
shopping_webview.getSettings().setAllowFileAccessFromFileURLs(true);
shopping_webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
shopping_webview.getSettings().setDomStorageEnabled(true);
shopping_webview.getSettings().setUseWideViewPort(true);
shopping_webview.getSettings().setLoadWithOverviewMode(true);
shopping_webview.getSettings().setLoadsImagesAutomatically(true);
shopping_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
shopping_webview.getSettings().setSupportMultipleWindows(true);
shopping_webview.getSettings().setBuiltInZoomControls(true);
shopping_webview.getSettings().setDisplayZoomControls(false);
shopping_webview.getSettings().setJavaScriptEnabled(true);
webviewLink.getSettings().setLoadsImagesAutomatically(true);
webviewLink.getSettings().setJavaScriptEnabled(true);
webviewLink.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webviewLink.loadUrl(postlink);
webviewLink.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO show you progress image
progressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO hide your progress image
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
load the Url with this way it's work for me in the same app..
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(_URL);
}
private class MyWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
}
I am facing problem with loading URL in web-view. Web-view shows blank because it is not logged in. How to access course file without login into moodle2.6 by using url.
Using this url format
http://example.com/pluginfile.php/4418/mod_resource/content/10/xx-t2.pdf
Here is my web-view code
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//progDailog.show();
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
//progDailog.dismiss();
}
});
webView.loadUrl("http://example.com/pluginfile.php/4418/mod_resource/content/10/xx-t2.pdf");
You need to append the pdf URL to Google Doc Viewer to open pdf in web view, Also you will need to enable JavaScript for your webview
public class MainActivity extends AppCompatActivity {
WebView webview;
String pageURL = "https://developer.android.com/guide/webapps/webview.html";
String pdf = "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"; //your pdf address
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptEnabled(true); // enable javascript
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//progDailog.show();
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
//progDailog.dismiss();
}
});
//webview.loadUrl(pageURL);
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf); //simply append pdf address to doc viewer
}
}
Sample PDF opened in webview
It seems that you're webclient is not calling their super methods, which could be one reason for the page to not load, use the following code to load the login page, which once signed in the user could view the intended pdf file.
webView.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);//<-- this is important when overriding
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);//<-- this is important when overriding
}
});
webView.loadUrl("https://lms.jsbl.com//pluginfile.php//4925//mod_resource//content//0//calendar_cal_605.pdf");
And also If you want you view a pdf using the webview you need append the following before your url so that the google plugin could be used to load the pdf
https://docs.google.com/gview?embedded=true&url=
(for this to work make sure you have added the following to your webview
webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setPluginState(PluginState.ON);)
According to this question some login form submit might not work on android webview so set all/some(check if your login works without it) on your webview to make the login work
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDatabasePath(dbpath); //check the documentation for info about dbpath
mWebView.getSettings().setMinimumFontSize(1);
mWebView.getSettings().setMinimumLogicalFontSize(1);
But if you know the credentials for the login You could follow the instruction on this site to inject a javascript to the webview which would fire the Login form submit on the webview and redirect to the pdf file directly
UPDATE 16/3/2018
Use the following code which will append the google pdf widget during a redirect
and has a pdf extension
boolean isInititialRedirectComplete = false;
boolean isPdfRedirectComplete = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
f-inal WebView webView = (WebView) findViewById(R.id.testWebView);
webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, final String url) {
super.onPageFinished(view, url);
if (url.substring(url.lastIndexOf(".")).equalsIgnoreCase(".pdf") && !isPdfRedirectComplete && isInititialRedirectComplete ){
isPdfRedirectComplete = true;
webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + url);
}
isInititialRedirectComplete = true;
}
});
webView.loadUrl(
"https://lms.jsbl.com//pluginfile.php//4925//mod_resource//content//0//calendar_cal_605.pdf");
}
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);
}
});
I am working with android app for the web view. It loads the webpage but i cant make more actions on the page using my app. when I am choosing a hyperlink from the page it shows a popup"complete the action using chrome,opera etc.." how can I use this without such browsers..I nedd to browse web contents using my app. how it possible??
I used the code
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
please help me since I am new to android and thank you.
wv.loadUrl(url);
wv.setWebViewClient(new MyWebViewClient());
Your WebViewCLient class would look like this:
class MyWebViewClient extends WebViewClient {
#Override
// show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webProg.setVisibility(View.GONE);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
}