Android Webview: Smaller Display Size Breaks Layout

I have an app that’s basically just displaying mobile website in an Android Webview, with some native bits for handling notification & navigation headers.

The issue is, when I change the Display Size setting (under Display) in an Android phone to anything smaller than Default, the content will be squeezed to the right side and left a blank space. I did a check with dev tool, and somehow the CSS’s width is set to 66.67% of parent’s by Android (in default it’s 100%) & a minor left padding is also added. However, if the Display Size setting is larger than default, there is none / very minor style degradation.

The interesting part is when similar app is made in iOS (just display mobile site), there’s no issue at all after changing the Display Size. So I’m pretty certain that the fix is limited to Android.

Is there any guidance to add code to anticipate these changes, or at least, completely disable the Display Size setting’s effects?

Permitir abrir popups dentro da webview no Android Studio

Olá! Estou criando uma webview e estou com um problema para abrir popups dentro da webview. Se eu abrir o site que estou usando no navegador google chrome, e clicar nesses links, o navegador me pede para permitir popups. Gostaria de reproduzir essa permissão dentro da webview. Esta é minha main activity:

import android.Manifest; import android.content.ActivityNotFoundException; import android.content.Intent; import; import; import; import android.os.Build; import; import; import; import; import; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.webkit.DownloadListener; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast;   public class MainActivity extends AppCompatActivity {      WebView printpagew;     //Classes do Upload da Imagem     private ValueCallback<Uri> mUploadMessage;     public ValueCallback<Uri[]> uploadMessage;     public static final int REQUEST_SELECT_FILE = 100;     private final static int FILECHOOSER_RESULTCODE = 1;     //Fim Classes do Upload da Imagem          //Classes de Refresh da Pagina     private SwipeRefreshLayout layoutRefresh;     //Fim Classes de Refresh da Pagina      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          printpagew = findViewById(;         layoutRefresh = this.findViewById(;  //refresh da webview         printpagew.loadUrl(""); // link de acesso         printpagew.loadUrl( "javascript:window.location.reload( true )" );         printpagew.getSettings().setAllowFileAccess(true);         WebSettings webSettings = printpagew.getSettings();         webSettings.setSaveFormData(true);         printpagew.getSettings().setCacheMode (WebSettings.LOAD_NO_CACHE); //nao carrega cache na apl         printpagew.getSettings().setAppCacheEnabled(true);         printpagew.getSettings().setPluginState(WebSettings.PluginState.ON);// libera o acesso aos plugins na webview         printpagew.getSettings().setLoadWithOverviewMode(true);  //ajusta a largura da pagina.         printpagew.getSettings().setSupportZoom(true);        // suporte a zoom         printpagew.getSettings().setBuiltInZoomControls(true); // permitir aplicar ao zooom         printpagew.getSettings().setDisplayZoomControls(false); // desativar os controles de zoom padrão na página         printpagew.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);  // barra de rolagem         printpagew.getSettings().setDomStorageEnabled(true);  // API de armazenamento DOM         printpagew.getSettings().setUseWideViewPort(true);   // Habilita layout responsivo         printpagew.getSettings().setLoadWithOverviewMode(true);  // Diminuir o zoom se a largura do conteúdo for maior que a viewport           // Habilita JavaScript         printpagew.getSettings().setJavaScriptEnabled(true);         // Fim Habilita JavaScript           // Executa navegador dentro da WebView         printpagew.setWebViewClient(new WebViewClient());         printpagew.setWebChromeClient(new WebChromeClient());         // Fim Executa navegador dentro da WebView           // Refresh da Pagina         layoutRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {             @Override             public void onRefresh() {                 if (printpagew.getUrl() != null) {                     printpagew.reload(); // write what happens after swipe refreshing                 }                 layoutRefresh.setRefreshing(false); //this line hides the refresh button after completing             }         });         // Fim Refresh da Pagina           // Download no app         printpagew.setDownloadListener(new DownloadListener() {             @Override             public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {                 Uri myUri = Uri.parse(url);                 Intent superIntent = new Intent(Intent.ACTION_VIEW);                 superIntent.setData(myUri);                 startActivity(superIntent);             }         });         // Fim Download no app           //Upload da imagem dentro da Web View         String permission = Manifest.permission.CAMERA;         int grant = ContextCompat.checkSelfPermission(this, permission);         if (grant != PackageManager.PERMISSION_GRANTED) {             String[] permission_list = new String[1];             permission_list[0] = permission;             ActivityCompat.requestPermissions(this, permission_list, 1);         }         printpagew.setWebChromeClient(new WebChromeClient()         {             // Para Android 3.0+ Devices             protected void openFileChooser(ValueCallback uploadMsg, String acceptType)             {                 mUploadMessage = uploadMsg;                 Intent i = new Intent(Intent.ACTION_GET_CONTENT);                 i.addCategory(Intent.CATEGORY_OPENABLE);                 i.setType("image/*");                 startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);             }             // Para Android Lollipop 5.0+ Devices             @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)             public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)             {                 if (uploadMessage != null) {                     uploadMessage.onReceiveValue(null);                     uploadMessage = null;                 }                  uploadMessage = filePathCallback;                  Intent intent = fileChooserParams.createIntent();                 try                 {                     startActivityForResult(intent, REQUEST_SELECT_FILE);                 } catch (ActivityNotFoundException e)                 {                     uploadMessage = null;                     Toast.makeText(MainActivity.this.getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();                     return false;                 }                 return true;             }             //Para Android 4.1 only             protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)             {                 mUploadMessage = uploadMsg;                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 intent.addCategory(Intent.CATEGORY_OPENABLE);                 intent.setType("image/*");                 startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);             }              protected void openFileChooser(ValueCallback<Uri> uploadMsg)             {                 mUploadMessage = uploadMsg;                 Intent i = new Intent(Intent.ACTION_GET_CONTENT);                 i.addCategory(Intent.CATEGORY_OPENABLE);                 i.setType("image/*");                 startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);             }         });      }      @Override     public void onActivityResult(int requestCode, int resultCode, Intent intent)     {         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)         {             if (requestCode == REQUEST_SELECT_FILE)             {                 if (uploadMessage == null)                     return;                 uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));                 uploadMessage = null;             }         }         else if (requestCode == FILECHOOSER_RESULTCODE)         {             if (null == mUploadMessage)                 return;             Uri result = intent == null || resultCode != MainActivity.RESULT_OK ? null : intent.getData();             mUploadMessage.onReceiveValue(result);             mUploadMessage = null;         }         else             Toast.makeText(MainActivity.this.getApplicationContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();     }     //Fim Upload dentro da WebView        // Classe shouldOverrideUrlLoading / onPage / onkey     private class HelloWebViewClient 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 webView, String url)         {             webView.loadUrl(url);             return false;         }          @Override         public void onPageFinished(WebView view, String url) {             // TODO Auto-generated method stub             super.onPageFinished(view, url);          }      }      @Override     public boolean onKeyDown(int keyCode, KeyEvent event)     { //if back key is pressed         if((keyCode == KeyEvent.KEYCODE_BACK)&& printpagew.canGoBack())         {             printpagew.goBack();             return true;          }          return super.onKeyDown(keyCode, event);      }     // Fim Classe shouldOverrideUrlLoading / onPage / onkey      }

Webview app not working without Internet access (Only Motorola phones) [on hold]

I have this simple app that is basically a Webview. The real code of my app is allocated on the webpage. To show how my app works, I have a router with a LAN, but without Internet access, because it doesn’t really need it. But my main issue here is that everything works fine in every android phone, but it doesn’t work on any Motorola phone.

Any ideas? I don’t even know if this question belongs here, but it was worth a shot.

PD: when there is Internet access everything works like a charm in every phone including Motorola.

What are the privacy implications of apps that use Android System WebView?

From what I’ve researched, Android System WebView supports cookies and HTML5 local storage.

When do those cookies and local storage items get cleared?

For example, Samsung Messenger (Samsung’s default SMS app) uses WebView to load web links (even in Android Nougat). If the loaded web page generates cookies and HTML5 local storage items, will those items be available:

  1. to every web page loaded within Samsung Messenger during that session?
  2. to every web page loaded within Samsung Messenger during later Messenger sessions?
  3. to other apps that use WebView?

Large contenteditable divs become terrible in Android 9 Pie webview

I have an App for notes taking based on HTML CSS and Javascript where text editing is made with contenteditable DIV. Each content page can contain formatted text, links, lists, tables, images.

With last update to Android 9 Pie of my Google Pixel XL the content editable of large notes become terribly slow, making the App essentially unusable. On small/normal contents slowness is almost unnoticeable.

When the App hangs for long time (like 30 s), Android asks if should kill it or wait. Letting wait the DIV is finally edited but any input (letters, new lines, etc.) takes few seconds to be executed.

Disabling all Javascript related to the text editing functions doesn’t change the behaviour. Changing text input (keyboard) and disabling Chrome App doesn’t change.

On AndroidStudio, running my App on simulator API 28 (Android 9 Pie) doesn’t have the problem.

Luckily I have another Pixel XL that I’m keeping on Android 8.1 Oreo that let me continue to use my app (I use it daily since 4 years). Same App runs ok on older devices with Android 6.0 and 7.0 app (Motorola G2 and G4).

Has anyone experienced this issue?

Android WebView JavaScript Enabled

I recently found an Android application, which uses a WebView with enabled JavaScript. In this webview I am able to browse from their provided FAQ page to twitter, and from twitter basically everywhere I want.

So my question is: Is this a vulnerability I need to report? Is XSS in updated WebViews still a thing, since I am able to escape the website of the app and browse anywhere I want?

I tried to find answers in Google, but did not manage to find any updated information.

Thanks in advance

Не открывается страница в WebView

Простейшее приложение WEbView. Но когда вставляю в .loadUrl(); ссылку на свой сайт, то выдает ошибку net::ERR_CLEARTEXT_NOT_PERMITTED Что это значит и как фиксить? Очень срочно, заранее спасибо.

solicitando uma impressão pelo WebView do android

Amigos, tenho uma aplicação que usa o WebView para acessar uma web página online. Nela tem um formulário e um botão para imprimir o conteúdo, porém ele não funciona. Acessando esta página por navegadores o tal botão funciona normalmente, mas dentro do aplicativo não. Sabem me dizer o porquê disso? ou melhor que isso, sabem uma solução?