Capturing android w...
 
Share:
Notifications
Clear all

Capturing android webview image and saving to png/jpeg

  

0
Topic starter

convert html table or  div to an image in jQuery and also in JavaScript. it will work very well in desktop and android devices and it supports downloading an image. but it not working in android web view app. when i click download button my runnable app should be stopped and exit. please give a correct soluton for this error.

9 Answers
1

Hi Vijay Ram, Please Check your WebView javaScriptEnabled is true? in Android WebView.

WebView.getSettings().setJavaScriptEnabled(true);

 

And also did you set Download Manager In WebView?

 

Hi

Thanks your reply. yes i checked both are enabled. its work fine view and download as desktop and mobile browser. i want to fix in my webview android app. error: view is work not downloading.when i click download yes my app closed automatically 

I think you haven't set the download destination folder for your download file. So that when you click on "Yes" the app is closing automatically.

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));

I found this on this blog. Request Write External Storage Permission for Save Files

And also you have to Request Write External Storage Permission for Save Files.

Hi brother,thanks your valuable reply.

yes,i used this source code for my app. with implement  codepedia. code in my html using elementor in wordpress site. work very well in desktop and mobile chrome browser.

I notice your msg. then i change my error..after set still my app is close automatically...

please fix this problem bro..

1

You can find the answer from codepedia.

yes i used this source code work very well in desktop and mobile browser. i got error downloading in android webview app

1

Hello Vijay Ram, I read the above comments. I think still you didn't solve the problem.

Before Answer your question Can you please share your code with us (Android Studio WebView MainActivity and AndroidManifest.xml).

And also to save files You have to add the following codes In webSettings.

webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
This post was modified 2 months ago by Danushka Sanjeewa
0
Topic starter

2nd

0
Topic starter

hi Danushka and  The Mask

thanks your reply... i notice your msg.i try also without elementor to paste html code in wordpress.i got same issues...i here by attach my code...

 

 Activity.Java

package com.xxxxx;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import android.Manifest;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.ContextMenu;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;



import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import static com.google.android.gms.common.internal.ImagesContract.URL;

public class MainActivity extends AppCompatActivity {


    String websiteURL = ""; // sets web url
    private WebView webview;
    SwipeRefreshLayout mySwipeRefreshLayout;
    private InterstitialAd mInterstitialAd;
    private AdView mAdView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        MobileAds.initialize(this, initializationStatus -> {});


        if( ! CheckNetwork.isInternetAvailable(this)) //returns true if internet available
        {
            //if there is no internet do this
            setContentView(R.layout.activity_main);
            //Toast.makeText(this,"No Internet Connection, Chris",Toast.LENGTH_LONG).show();

            new AlertDialog.Builder(this) //alert the person knowing they are about to close
                    .setTitle("No internet connection available")
                    .setMessage("Please Check you're Mobile data or Wifi network.")
                    .setPositiveButton("Ok", (dialog, which) -> finish())
                    //.setNegativeButton("No", null)
                    .show();

        }
        else
        {
            //Webview stuff

            webview = findViewById(R.id.webView);

            webview.loadUrl(URL);
            Log.v("TheURL", URL);
            webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
            webview.loadUrl(websiteURL);
            WebSettings webSetting = webview.getSettings();
            webSetting.setJavaScriptEnabled(true);
            webSetting.setDomStorageEnabled(true);
            webview.setWebViewClient(new WebViewClientDemo());
            webSetting.setDisplayZoomControls(true);
            webSetting.setSupportMultipleWindows(false);
            webSetting.setLoadsImagesAutomatically(true);
            webSetting.setLoadWithOverviewMode(true);
            webview.setDrawingCacheEnabled(true);
            webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
            webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
            webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
            webSetting.setUseWideViewPort(true);
            webSetting.setSaveFormData(true);
            webSetting.setAllowFileAccess(true);
            webSetting.setAllowContentAccess(true);
            webSetting.setMediaPlaybackRequiresUserGesture(false);
            registerForContextMenu(webview);

        }

        //Swipe to refresh functionality
        mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);

        mySwipeRefreshLayout.setOnRefreshListener(
                () -> webview.reload()

        );

        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.M){
            if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED){

                Log.d("permission","permission denied to WRITE_EXTERNAL_STORAGE - requesting it");
                String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
                requestPermissions(permissions,1);
            }


        }

//handle downloading
        webview.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                        DownloadDialog(url, userAgent, contentDisposition, mimetype);
                    } else {
                        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                    }
                } else {
                    DownloadDialog(url, userAgent, contentDisposition, mimetype);
                }
            }
        });


        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
                new InterstitialAdLoadCallback() {
                    @Override
                    public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                        // The mInterstitialAd reference will be null until
                        // an ad is loaded.
                        mInterstitialAd = interstitialAd;
                        mInterstitialAd.show(MainActivity.this);
                    }

                    @Override
                    public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                        // Handle the error
                        mInterstitialAd = null;
                    }

                });

    }   private void DownloadDialog(String url, String userAgent, String contentDisposition, String mimetype) {
        final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Downloading...")
                .setMessage("Do you want to download" + ' ' + " " + filename + "" + ' ')
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                        String cookie = CookieManager.getInstance().getCookie(url);
                        request.addRequestHeader("Cookie", cookie);
                        request.addRequestHeader("User-Agent", userAgent);
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                        DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
                        manager.enqueue(request);

                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                    }
                })
                .show();
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        WebView.HitTestResult webViewHitTestResult = webview.getHitTestResult();
        if(webViewHitTestResult.getType()== WebView.HitTestResult.IMAGE_TYPE ||
                webViewHitTestResult.getType()==WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
            menu.setHeaderTitle("Download");
            menu.setHeaderIcon(R.drawable.down_img);
            menu.add(0,1,0,"Save - Download Image")
                    .setOnMenuItemClickListener(menuItem -> {
                        String downloadImageurl = webViewHitTestResult.getExtra();
                        if (URLUtil.isValidUrl(downloadImageurl)){
                            DownloadManager.Request request=new DownloadManager.Request(Uri.parse(downloadImageurl));
                            request.allowScanningByMediaScanner();
                            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
                            DownloadManager downloadManager=(DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                            downloadManager.enqueue(request);
                            Toast.makeText(MainActivity.this, "Downloading...", Toast.LENGTH_SHORT).show();
                        }
                        else{
                            Toast.makeText(MainActivity.this, "Sorry...Check Internet Conncecction or Try again Later", Toast.LENGTH_SHORT).show();
                        }
                        return false;
                    });
        }

    }

    private class WebViewClientDemo extends WebViewClient {
        @Override
        //Keep webview in app when clicking links
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mySwipeRefreshLayout.setRefreshing(false);

        }
    }


    //set back button functionality
    @Override
    public void onBackPressed() { //if user presses the back button do this
        if (webview.isFocused() && webview.canGoBack()) { //check if in webview and the user can go back
            webview.goBack(); //go back in webview
        } else { //do this if the webview cannot go back any further

            new AlertDialog.Builder(this) //alert the person knowing they are about to close
                    .setTitle("EXIT")
                    .setMessage("Are you sure. You want to close this app?")
                    .setPositiveButton("Yes", (dialog, which) -> finish())
                    .setNegativeButton("No", null)
                    .show();
        }
    }

   }

class CheckNetwork {

    private static final String TAG = CheckNetwork.class.getSimpleName();

    public static boolean isInternetAvailable(Context context)
    {
        NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

        if (info == null)
        {
            Log.d(TAG,"no internet connection");
            return false;
        }
        else
        {
            if(info.isConnected())
            {
                Log.d(TAG," internet connection available...");
                return true;
            }
            else
            {
                Log.d(TAG," internet connection");
                return true;
            }

        }
    }
}

 

Manifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns//schemas.android.com/apk/res/android"
    xmlns//schemas.android.com/tools"
    package="com.xxxt">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="28"
        tools:ignore="ScopedStorage"/>

    <application
        android:screenOrientation="portrait"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.xxxx">
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-378027501042xxxx"/>
    </application>
0
Topic starter

hi Danushka and  The Mask

thanks your reply... i notice your msg.i try also without elementor to paste html code in wordpress.i got same issues...i here by attach my code...

 

 Activity.Java

package com.xxxxx;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import android.Manifest;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.ContextMenu;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;



import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import static com.google.android.gms.common.internal.ImagesContract.URL;

public class MainActivity extends AppCompatActivity {


    String websiteURL = ""; // sets web url
    private WebView webview;
    SwipeRefreshLayout mySwipeRefreshLayout;
    private InterstitialAd mInterstitialAd;
    private AdView mAdView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        MobileAds.initialize(this, initializationStatus -> {});


        if( ! CheckNetwork.isInternetAvailable(this)) //returns true if internet available
        {
            //if there is no internet do this
            setContentView(R.layout.activity_main);
            //Toast.makeText(this,"No Internet Connection, Chris",Toast.LENGTH_LONG).show();

            new AlertDialog.Builder(this) //alert the person knowing they are about to close
                    .setTitle("No internet connection available")
                    .setMessage("Please Check you're Mobile data or Wifi network.")
                    .setPositiveButton("Ok", (dialog, which) -> finish())
                    //.setNegativeButton("No", null)
                    .show();

        }
        else
        {
            //Webview stuff

            webview = findViewById(R.id.webView);

            webview.loadUrl(URL);
            Log.v("TheURL", URL);
            webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
            webview.loadUrl(websiteURL);
            WebSettings webSetting = webview.getSettings();
            webSetting.setJavaScriptEnabled(true);
            webSetting.setDomStorageEnabled(true);
            webview.setWebViewClient(new WebViewClientDemo());
            webSetting.setDisplayZoomControls(true);
            webSetting.setSupportMultipleWindows(false);
            webSetting.setLoadsImagesAutomatically(true);
            webSetting.setLoadWithOverviewMode(true);
            webview.setDrawingCacheEnabled(true);
            webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
            webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
            webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
            webSetting.setUseWideViewPort(true);
            webSetting.setSaveFormData(true);
            webSetting.setAllowFileAccess(true);
            webSetting.setAllowContentAccess(true);
            webSetting.setMediaPlaybackRequiresUserGesture(false);
            registerForContextMenu(webview);

        }

        //Swipe to refresh functionality
        mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);

        mySwipeRefreshLayout.setOnRefreshListener(
                () -> webview.reload()

        );

        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.M){
            if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED){

                Log.d("permission","permission denied to WRITE_EXTERNAL_STORAGE - requesting it");
                String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
                requestPermissions(permissions,1);
            }


        }

//handle downloading
        webview.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                        DownloadDialog(url, userAgent, contentDisposition, mimetype);
                    } else {
                        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                    }
                } else {
                    DownloadDialog(url, userAgent, contentDisposition, mimetype);
                }
            }
        });


        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
                new InterstitialAdLoadCallback() {
                    @Override
                    public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                        // The mInterstitialAd reference will be null until
                        // an ad is loaded.
                        mInterstitialAd = interstitialAd;
                        mInterstitialAd.show(MainActivity.this);
                    }

                    @Override
                    public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                        // Handle the error
                        mInterstitialAd = null;
                    }

                });

    }   private void DownloadDialog(String url, String userAgent, String contentDisposition, String mimetype) {
        final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Downloading...")
                .setMessage("Do you want to download" + ' ' + " " + filename + "" + ' ')
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                        String cookie = CookieManager.getInstance().getCookie(url);
                        request.addRequestHeader("Cookie", cookie);
                        request.addRequestHeader("User-Agent", userAgent);
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                        DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
                        manager.enqueue(request);

                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                    }
                })
                .show();
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        WebView.HitTestResult webViewHitTestResult = webview.getHitTestResult();
        if(webViewHitTestResult.getType()== WebView.HitTestResult.IMAGE_TYPE ||
                webViewHitTestResult.getType()==WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
            menu.setHeaderTitle("Download");
            menu.setHeaderIcon(R.drawable.down_img);
            menu.add(0,1,0,"Save - Download Image")
                    .setOnMenuItemClickListener(menuItem -> {
                        String downloadImageurl = webViewHitTestResult.getExtra();
                        if (URLUtil.isValidUrl(downloadImageurl)){
                            DownloadManager.Request request=new DownloadManager.Request(Uri.parse(downloadImageurl));
                            request.allowScanningByMediaScanner();
                            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
                            DownloadManager downloadManager=(DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                            downloadManager.enqueue(request);
                            Toast.makeText(MainActivity.this, "Downloading...", Toast.LENGTH_SHORT).show();
                        }
                        else{
                            Toast.makeText(MainActivity.this, "Sorry...Check Internet Conncecction or Try again Later", Toast.LENGTH_SHORT).show();
                        }
                        return false;
                    });
        }

    }

    private class WebViewClientDemo extends WebViewClient {
        @Override
        //Keep webview in app when clicking links
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mySwipeRefreshLayout.setRefreshing(false);

        }
    }


    //set back button functionality
    @Override
    public void onBackPressed() { //if user presses the back button do this
        if (webview.isFocused() && webview.canGoBack()) { //check if in webview and the user can go back
            webview.goBack(); //go back in webview
        } else { //do this if the webview cannot go back any further

            new AlertDialog.Builder(this) //alert the person knowing they are about to close
                    .setTitle("EXIT")
                    .setMessage("Are you sure. You want to close this app?")
                    .setPositiveButton("Yes", (dialog, which) -> finish())
                    .setNegativeButton("No", null)
                    .show();
        }
    }

   }

class CheckNetwork {

    private static final String TAG = CheckNetwork.class.getSimpleName();

    public static boolean isInternetAvailable(Context context)
    {
        NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

        if (info == null)
        {
            Log.d(TAG,"no internet connection");
            return false;
        }
        else
        {
            if(info.isConnected())
            {
                Log.d(TAG," internet connection available...");
                return true;
            }
            else
            {
                Log.d(TAG," internet connection");
                return true;
            }

        }
    }
}

 

Manifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns//schemas.android.com/apk/res/android"
    xmlns//schemas.android.com/tools"
    package="com.xxxt">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="28"
        tools:ignore="ScopedStorage"/>

    <application
        android:screenOrientation="portrait"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.xxxx">
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-378027501042xxxx"/>
    </application>
0
Topic starter

🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 still iam waiting bro's

In your Manifest.xml remove the maxSdkVersion and add following code in your .MainActivity.

<activity android:name=".MainActivity"
android:hardwareAccelerated="true"
>

In your (build.gradle(:app)) change compileSdkVersion, minSdkVersion and targetSdkVersion to latest one.

Hi Bro,

Thaks Your Reply. i Notice your solution message and i remove maxSdk version and add hardware accelerated ='true' in main activity..after i get same issues..

here i attach my html code..it support very well and download in desktop and mobile browser. still my app closed automatically after click download button nottification message  'yes'

<html>
<head>
<style>

.tablepress-id-55 tbody td {
font-family: Monoton;

font-size: 16px; font-weight: bold; color: #000; }

.tablepress-id-55 th {
padding: 1px;
border: 1px solid black;
border-collapse: collapse;
}
.tablepress-id-55 td {
padding: 1px;
border: 1px solid black;
border-collapse: collapse;
}

.tablepress thead th {
background-color: #F63434;
font-family: Helvetica;
font-size: 20px;
font-weight: bold;
color: #000;
}
.tablepress .odd td {
background-color: #FFFFFF;
}

.tablepress .even td {
background-color: #FFFFFF;
}
.tablepress-id-55 .highlight
{
font-weight: bold;
font-size: 12px;
color: #Ce200b;
}
.tablepress-id-55 .row-2 td {
background-color: #A9F760
}
.tablepress-id-55 .row-2 .column-1 {
background-color: #FA6D6D;
}
.tablepress-id-55 .column-1 {
background-color: #F68434 ;
}

.tablepress-id-55 tbody td:first-child {
padding: 1px;
background-color: #A9F760
;
}

</style>
<meta charset="UTF-8">

<meta name="viewport" content="width=1200">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.js"></script>
<script src="https://raw.githubusercontent.com/tsayen/dom-to-image/master/src/dom-to-image.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js"></script>
<script src="https://raw.githubusercontent.com/hongru/canvas2image/master/canvas2image.js"></script>
</head>
<body>
<center>
<div id="myHtml" width="100%" >
[table id=55 /]

</div>

<input id="btn_convert" type="button" value="Download Image" />

<br />
<b> (Note : Use Chrome Browser ( www.kllotteryresults.in ) to download a chart image immediately after result using mobile or Desktop...<br>update will fix soon in our Android App)</b>

</center>
<script>
$(document).ready(function () {

$("#btn_convert").on('click', function () {
html2canvas(document.getElementById("myHtml"),
{
allowTaint: true,
useCORS: true
}).then(function (canvas) {
var anchorTag = document.createElement("a");
document.body.appendChild(anchorTag);
anchorTag.download = "2020-2021 Three Digit Year Chart";
anchorTag.href = canvas.toDataURL();
anchorTag.target = '_blank';
anchorTag.click();
});
});

});

</script>

</body>
</html>

0

Hi Vijay Ram. Sorry For the late. Here you can use this Android WebView App For Any Work – Source code for your project. Only you have to do is changing the web URL and package name.

I think this will solve your problem. Here is the full source code.

This WebView App Features:

  • All codes are on one page – So that you can learn quickly.
  • Splash Screen
  • No Internet & Error Screen with Dialog Message
  • Earn money from AdMob (Interstitial Ads & Banner Ads)
  • Ask Permissions / Runtime permissions
  • File Upload/Download
  • Download Manager: Download any file
  • Media Support: supports video (YouTube, Vimeo, HTML5 videos etc…), audio(.mp3, .wav etc…), all image format and animated image (.gif).
  • Push Notification: Push notification with Google Firebase cloud messaging
  • Open External Links in browser/Application and only your sites links open in WebView
  • Full-screen video View
  • Pull-to-Refresh webpages
  • Download Alert
  • Long back press exit is available when a user tries to exit the app
  • Responsive design (portrait, landscape, handling orientation change)

Read More...

This post was modified 1 month ago by Danushka Sanjeewa

Hi Bro

Thanks for your reply. i try this source code and i get same issues..all are work perfectly like admob, downloading.... But not support html table downloading into image..

Here i attach my html code

 <html>
<head>
<style>

.tablepress-id-55 tbody td {
font-family: Monoton;

font-size: 16px; font-weight: bold; color: #000; }

.tablepress-id-55 th {
padding: 1px;
border: 1px solid black;
border-collapse: collapse;
}
.tablepress-id-55 td {
padding: 1px;
border: 1px solid black;
border-collapse: collapse;
}

.tablepress thead th {
background-color: #F63434;
font-family: Helvetica;
font-size: 20px;
font-weight: bold;
color: #000;
}
.tablepress .odd td {
background-color: #FFFFFF;
}

.tablepress .even td {
background-color: #FFFFFF;
}
.tablepress-id-55 .highlight
{
font-weight: bold;
font-size: 12px;
color: #Ce200b;
}
.tablepress-id-55 .row-2 td {
background-color: #A9F760
}
.tablepress-id-55 .row-2 .column-1 {
background-color: #FA6D6D;
}
.tablepress-id-55 .column-1 {
background-color: #F68434 ;
}

.tablepress-id-55 tbody td:first-child {
padding: 1px;
background-color: #A9F760
;
}

</style>
<meta charset="UTF-8">

<meta name="viewport" content="width=1200">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.js"></script>
<script src="https://raw.githubusercontent.com/tsayen/dom-to-image/master/src/dom-to-image.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js"></script>
<script src="https://raw.githubusercontent.com/hongru/canvas2image/master/canvas2image.js"></script>
</head>
<body>
<center>
<div id="myHtml" width="100%" >
[table id=55 /]

</div>

<input id="btn_convert" type="button" value="Download Image" />

<br />
<b> (Note : Use Chrome Browser ( www.kllotteryresults.in ) to download a chart image immediately after result using mobile or Desktop...<br>update will fix soon in our Android App)</b>

</center>
<script>
$(document).ready(function () {

$("#btn_convert").on('click', function () {
html2canvas(document.getElementById("myHtml"),
{
allowTaint: true,
useCORS: true
}).then(function (canvas) {
var anchorTag = document.createElement("a");
document.body.appendChild(anchorTag);
anchorTag.download = "2020-2021 Three Digit Year Chart";
anchorTag.href = canvas.toDataURL();
anchorTag.target = '_blank';
anchorTag.click();
});
});

});

</script>

</body>
</html>
  

0
Topic starter

Hello,

please fix the error. please can anyone reply?