WebView user agent - android

I have WebView which loads one mobile site, I need send to user agent to the server how it to realize?
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://searchmp3.mobi/");
mWebView.setWebViewClient(new HelloWebViewClient());

Checkout the setUserAgentString() method in the WebSettings, e.g.
mWebView.getSettings().setUserAgentString("My user agent string, here");

try this one
WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.loadUrl("http://www.google.com");

Related

web view don't load when language change but in chrome it does reload

i am making a web view app where there is a language tabs on header like spinner when i change language in chrome it do refresh and language changes but in web view it don't detect language change on same link and don't restart until manually restart i have enabled java script and sharing some code i search every where but didn't get any solution. and the languages load at same time when page load.
mWebView = (AdvancedWebView) findViewById(R.id.webView);
mWebView.loadDataWithBaseURL(null,URL,"text/html", "utf-8", null);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setCookiesEnabled(true);
mWebView.setDesktopMode(true);
mWebView.setThirdPartyCookiesEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setSaveFormData(true);
mWebView.getSettings().setAllowContentAccess(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setClickable(true);
mWebView.setWebChromeClient(new WebChromeClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setDefaultTextEncodingName("utf-8");

Android: How to force WebView to play a video from youtube?

i want to play a youtube video using embeded url in webview in my app but the video is opened automatically in youtube application that is insatlled in my phone instead of played in webview in the activity
here is my code
WebView mWebview = (WebView) findViewById(R.id.mwebview);
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.getSettings().setBuiltInZoomControls(true);
mWebview.getSettings().setSupportZoom(false);
mWebview.loadUrl("http://www.youtube.com/embed/" + video.youtube_id);
i find the answer
mWebview = (WebView) findViewById(R.id.mwebview);
mWebview.setInitialScale(1);
mWebview.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebview.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = mWebview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(false);
webSettings.setUseWideViewPort(true);
webSettings.setAppCacheEnabled(true);
webSettings.setSupportMultipleWindows(true);
mWebview.loadUrl("http://www.youtube.com/embed/" + video.youtube_id);

android webview show credentials popup

Here is the link where I want to login:
http://audidome-dev.webspaces.vektorrausch.net/app/login.php
and in normal browser it looks so
but I can't get this popup in my WebView.
Here is my code:
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setVisibility(View.VISIBLE);
mWebView.loadUrl("http://audidome-dev.webspaces.vektorrausch.net/app/login.php");
WebView won't display this pop-up. It will ask you for the credentials and it's up to you to fill the credentials (display the pop-up).

save android WebView cache and load no internet

I search and no find any learn for my questions please help.
my WebView code :
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
WebView webView = (WebView) findViewById(R.id.webView1);
initWebView(webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
webView.getSettings().setAppCachePath("/cache/");
webView.getSettings().setAppCacheEnabled(true);
webView.loadUrl("http://google.com");
webView.setWebViewClient(new WebViewClient());
Use this
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Activity.CONNECTIVITY_SERVICE);
if(connectivityManager.getActiveNetworkInfo().isConnected()){
mfnWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mfnWebView.loadUrl(url);
}
else{
mfnWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mfnWebView.loadUrl(url);
}
Mandatory permissions :- INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE

android webview unset default browser

I use the following to show a webpage in a webview
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
WebView webView = (WebView)findViewById(R.id.webView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webView.loadUrl("http://www.bbc.co.uk");
}
It works perfect and even has pinch and zoom however When i click to go to another webpage via a link it opens it in the default browser instead of the webview
How to i achieve this. I have read many articles on this but cant understand where i need to insert the commands
Any help appreciated
Mark
thanks very much for the link above the following works perfect
myWebView.loadUrl("http://someurl.com");
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
return false;
}
});

Categories

Resources