0

I want to show the download app now button on the website, but I want to hide that from webview android app. it should show up only on the website but not inside the webview app.

Is it possible? if so how?

css file

.desk {
    width: 250px;
    height: 70px;
    color: white;
    font-family: sans-serif;
    text-decoration: none;
    font-size: 1.5em;
    position: fixed;
    transform: translate(35%, -25%);
    top: 50%; 
    right: 50%;
}
@media screen and (max-width : 906px) {
     .desk {
          visibility:hidden;
     }
}

html

      <div class="desk">
 <a href="./download.php?file=app.apk" class="buttonDownload"><img src="img/playstore-app.jpg"  height="35" width="120">
</a>  

 </div>

Main_activity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (WebView) findViewById(R.id.webView);
    WebSettings mWebSettings = webView.getSettings();
    webView.setWebViewClient(new WebViewClient());
    mWebSettings.setJavaScriptEnabled(true);
    mWebSettings.setSupportZoom(false);
    mWebSettings.setAllowFileAccess(true);
    mWebSettings.setAllowFileAccess(true);
    mWebSettings.setAllowContentAccess(true);
    webView.loadUrl("https://worldfamoushub.com");
    webView.loadUrl("javascript:document.getElementsByClassName('desk')[0].style.display='none';");
    webView.setWebChromeClient(new WebChromeClient() {
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
            if (mUMA != null) {
                mUMA.onReceiveValue(null);
            }
            mUMA = filePathCallback;
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCM);
                } catch (IOException ex) {
                    Log.e("Webview", "Image file creation failed", ex);
                }
                if (photoFile != null) {
                    mCM = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("*/*");
            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[]{takePictureIntent};
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
            startActivityForResult(chooserIntent, FCR);
            return true;
        }
    });

}

The problem is it will appear on all mobile. I want this button to be disappeared from android webview. Is it possible to show it in the mobile web browser but not inside the webview app?

Samuel
  • 1
  • 3
  • Is this what you're looking for? https://stackoverflow.com/questions/3029926/any-way-to-hide-elements-from-webview-android – Anis R. Dec 02 '19 at 20:11
  • Related: [Detect android webview](https://stackoverflow.com/q/31848320/295004) – Morrison Chang Dec 02 '19 at 20:21
  • Try this: [Detecting mobile device in JavaScript](https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device) – PiNaKa30 Dec 03 '19 at 05:02
  • can u point out the error in the code main_activity.java? webView.loadUrl("javascript:document.getElementsByClassName('desk')[0].style.display='none';"); ... this doesn't seems to be doing its job correctly. – Samuel Dec 03 '19 at 17:10

0 Answers0