How to make webview website amp - android

WebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = WebView.getSettings();
webSettings.setJavaScriptEnabled(true);
WebView.loadUrl("http://zzzzzz.com/");
WebView.setWebViewClient(new com.barometer.app.MyAppWebViewClient(){
#Override
public void onPageFinished(WebView view, String url) {
//hide loading image
findViewById(R.id.progressBar1).setVisibility(View.GONE);
//show webview
findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
}});
The code can only call the web with the mobile version. I want to call my web amp. How to?

Related

in webview external link not work in my app

I have a problem with webview. In my app when i click a link it open with the default browser. But I want the link open with my own app. Please help how I do this
public class MainActivity extends AppCompatActivity {
private WebView webView ;
#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.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.somoynews.tv/");
}
}
Try this :
webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://www.somoynews.tv/");
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return false;
}
});
}

Web View not working with some specific url

public class MainActivity extends AppCompatActivity {
String url = "https://www.pinterest.com";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
}
});
webView.loadUrl(url);
}
}
Web View is not loading "https://www.pinterest.com" within the application but it was working with chrome browser using intent. I tried of other urls it's working. While loading "https://www.pinterest.com" using webview, getting the output screen like below
You try this:
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.pinterest.com/");
In manifest:
android:hardwareAccelerated="true"
set the JavascriptEnabled and AllowContentAccess and setDomStorageEnabled to true in settings

link not loading properly in android N webview

I want open this link (http://e-sign-poc.s3-website-us-west-2.amazonaws.com/) like mobile browser using webview
mWebview = (WebView) findViewById(R.id.wb_sample);
WebSettings webSettings = mWebview.getSettings(); webSettings.setJavaScriptEnabled(true);
mWebview.setWebChromeClient(new WebChromeClient());
mWebview.setWebViewClient(new WebViewClient());
mWebview.loadUrl("http://e-sign-poc.s3-website-us-west-2.amazonaws.com/");
This link not loading properly in webview, but this link works perfectly in telegram webview
Wait for some time after you load URL to WebView
It will work perfectly in my device
or
Try with this code
url = "http://e-sign-poc.s3-website-us-west-2.amazonaws.com/" +
"";
linearLayout.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(url);
Try with it -
webView = (WebView) findViewById(R.id.wvTest);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient(){
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
progressBar.setProgress(view.getProgress());
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
webView.loadUrl("https://www.example.com");

Android Webview vs Android Chrome Browser

I am trying to load a web page in a web view, I am able to do that, however there is an a button that allows you to upload a file. This button works fine when I load the page in the Chrome app on android and it opens the file browser, how ever on web view nothing happens. is it possible to use a chrome for web view, or some how get this button to trigger the file chooser in from the web view?
I have tried changing the web view options to enable javascript ect, below is the code for the webactivity:
public class WebActivity extends Activity {
Button b1;
WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
b1=(Button)findViewById(R.id.button);
wv=(WebView)findViewById(R.id.webView);
//wv1.setWebViewClient(new MyBrowser());
wv.setWebChromeClient(new WebChromeClient());
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
wv.loadUrl("MY WEBSITE URL");
wv.setWebChromeClient(new WebChromeClient());
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
if (url.startsWith("tel:") || url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
});
}
});
}
}
Try the below code.
WebView wv;
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
wv.loadUrl("YOUR URL HERE");
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
if (url.startsWith("tel:") || url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
});
wv.setWebChromeClient(new WebChromeClient());
Hope this will help you.
There are some options that are not enabled by default, most likely you don't have javascript.
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

WebView doesn't mantain login session

I have a browsable webview but unfortunately when I open a new page inside the webview i loose the login state and have to login again.
here my code:
wv = (WebView) findViewById(R.id.webArea);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
CookieManager.setAcceptFileSchemeCookies(true);
}
CookieSyncManager.createInstance(Home.this);
CookieSyncManager.getInstance().startSync();
dialog = new ProgressDialog(this);
dialog.setMessage("Loading");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadsImagesAutomatically(true);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
dialog.show();
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
});
wv.loadUrl(url);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setAllowFileAccess(true);
What's wrong?
Try this to set cookieSyncManager -
CookieSyncManager.createInstance(mWebView.getContext());
If doesn't work, then we will have to check how your URL navigates.

Categories

Resources