How to load a string from strings.xml inside webview class - android

I have a class to load webpage:
webView = (WebView) findViewById(R.id.login_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://google.com");
I want to load a string from strings.xml instead of http://google.com. How can I do this ?

Just change your current code to this
webView = (WebView) findViewById(R.id.login_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(getResources().getString(R.string.url));

You just need to do that
String url = getResources().getString(R.string.url);

Related

webview from json string loadurl() android

i want to load url for webview from my json string. but i don't understanding what i need to do for that. i'm trying to load url using getIntent().getExtras().getString("anime_img"); but it's not working. how i can do that? i have json data for the url. here i want to load this image url in webview to open Webview Client.
JSON Data:
image: "https://website.com/library/2019/11/03/1572813810_6.jpg"
my code is:
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(new myWebclient());
mainWebView.loadUrl(getIntent().getExtras().getString("anime_img"));
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
// Recieve data
String webview = getIntent().getExtras().getString("anime_img");
TextView tv_name = findViewById(R.id.aa_anime_name);
// setting values to each view
tv_name.setText(webview);
how i can load the webview url from my json data?
What do you send to in anime_img key? Is the " https://website.com/library/2019/11/03/1572813810_6.jpg "data returning?
So why do you show it in webview? You can display it using libraries such as Glide, Picasso in Imageview. Show this libraries. Glide , Picasso
If you say, I'll show it on webview.
// Recieve data
String webviewUrl = getIntent().getExtras().getString("anime_img");
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(webSettings);
mainWebView.loadUrl(webviewUrl);
You can'll try this.
after adding this code my problems has been solved :)
String webviewUrl = getIntent().getExtras().getString("anime_img");
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(new myWebclient());
mainWebView.loadUrl(webviewUrl);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
special thanks to fevziomurtekin

Android Studio Assets file cannot be accessed in WebView

I have been trying to figure out almost 2 weeks.
I have read previous posts and tried the proposed solutions but they didn't work for me.
Iam using Android Studio, I need Webview to access a local Jpg stored in Android Assets file.
Here is my code:
webView = (WebView) findViewById(R.id.webview);
startWebView("file:///android_asset/railchinese.jpg");
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
private void startWebView(String url) {
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
Here is the Assets location screen:
Kindlly let me know where is the mistake?..
Try this
String htmlData="<img src= railchinese.png>";
webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);

Pdf view android studio

Hello community wanted to know how to view a PDF file in android api eight studio try these codes but can not = (someone tell me what's wrong? ..
I get all the WebView blank
  thanks
WebView wv = (WebView)findViewById(R.id.webView2);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});
wv.loadUrl("www.ues.mx/Docs/alumnos/movilidad/Ejemplo%20de%20Curr%C3%ADculum%20Vitae.pdf");
wv.getSettings().setUseWideViewPort(true);
another way
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("www.ues.mx/Docs/alumnos/movilidad/Ejemplo%20de%20Curr%C3%ADculum%20Vitae.pdf");
setContentView(webview);
PluginsEnabled replaced
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
not work in any way help!
WebView cannot display PDF documents in Android.
You can handle the pdf to either download it and then open a 3rd party app as shown here.
Or you can also use Google Drive viewer.
String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);

How can I read special character in webview?

I am developing an article managing android application, where articles are parsed through JSON.
All the values that are parsed by JSON are loaded in web view, but there are some special character that are not read by WebView.
{
web1 = (WebView) findViewById(R.id.webView2);
web1.setWebViewClient(new myWebClient());
web1.getSettings().setJavaScriptEnabled(true);
web1.loadData(c,"text/html", "UTF-32");
}
you can do like this way,
WebView webview = new WebView(collection.getContext());
webview.loadDataWithBaseURL(url, textWithQuotesIn, "text/html", "UTF-8", url);

android/java replace string to bold or some color in webview in html

i have a string ticker..
ticker="hdfc:123:-1.90 tcc:231:+1.3 as continue to hundreds of
ticker will get from the server. i just want to bold the name... so help me to find my solution.....
here is my code...
tiker = TickerConnection.getInstance().Ticker();
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);String summary = "<html><body><MARQUEE>"+tiker+"</MARQUEE></body></html>";
mWebView.loadData(summary, "text/html", "utf-8");
hey following is ur solution... u jst have to add tag <b>
tiker = TickerConnection.getInstance().Ticker();
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);String summary = "<html><body><MARQUEE><b>"+tiker+"</b></MARQUEE></body></html>";
mWebView.loadData(summary, "text/html", "utf-8");

Categories

Resources