How to download file in url Android 8 Oreo

How to download file in URL Android 8 Oreo.




new DownloadFileFromURL(position).execute(data.get(url));

private class DownloadFileFromURL extends AsyncTask<String, String, String> {
    private ProgressDialog p;
    private int pos = 0;

    public DownloadFileFromURL(int p) {
        pos = p;
    }

    @Override    protected void onPreExecute() {
        super.onPreExecute();
        p = new ProgressDialog(context);
        p.setMessage("Downloading 0%");
        p.setIndeterminate(false);
        p.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        p.setCancelable(false);
        p.show();
    }

    @Override    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
        p.setMessage("Downloading " + values[0] + "%");
    }

    @Override    protected String doInBackground(String... f_url) {
        int count;
        String filename = f_url[0];
        String[] parts = filename.split("/");
        String part2 = parts[parts.length - 1];
        Boolean isSDPresent = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
        File myNewFolder = null;
        if (isSDPresent) {
            String newFolder = "/patelwala";
            String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
            myNewFolder = new File(extStorageDirectory + newFolder);
            if (myNewFolder.exists()) {
            } else {
                myNewFolder.mkdirs();
            }
        } else {
            String newFolder = "patelwala";
            myNewFolder = context.getDir(newFolder, Context.MODE_PRIVATE);
            if (!myNewFolder.exists()) {
                myNewFolder.mkdirs();
            }
        }
        try {
            System.out.println("Downloading");
            URL url = new URL(f_url[0]);

            URLConnection conection = url.openConnection();
            conection.connect();
            // getting file length            int lenghtOfFile = conection.getContentLength();
            // input stream to read file - with 8k buffer            InputStream input = new BufferedInputStream(url.openStream(), 8192);
            // Output stream to write file            OutputStream output = new FileOutputStream(myNewFolder + "/" + part2);
            byte data[] = new byte[1024];

            long total = 0;
            while ((count = input.read(data)) != -1) {
                //if (!Webservice.isCancelled) {                total += count;

                // writing data to file                publishProgress("" + (int) ((total * 100) / lenghtOfFile));
                output.write(data, 0, count);
              /*  } else {                    break;                }*/
            }
            // flushing output            output.flush();
            // closing streams            output.close();
            input.close();

        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }

        return myNewFolder + "/" + part2;
    }


    /**     * After completing background task     **/    @Override    protected void onPostExecute(String s) {
        p.dismiss();
        openDocument(s);
    }

}



public void openDocument(String name) {
    if (co == 0) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File(name);
        String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
        String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (extension.equalsIgnoreCase("") || mimetype == null) {
            // if there is no extension or there is no definite mimetype, still try to open the file            intent.setDataAndType(Uri.fromFile(file), "text*//*");
        } else {
            intent.setDataAndType(Uri.fromFile(file), mimetype);
        }
        // custom_alert_dialog message for the intent        context.startActivity(Intent.createChooser(intent, "Choose an Application:"));
    } else {
        co = 0;

        File f = new File(name);
        Uri uri = Uri.parse("file://" + f.getAbsolutePath());
        Intent share = new Intent(Intent.ACTION_SEND);
        //  share.putExtra(Intent.EXTRA_STREAM, uri);        String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(f).toString());
        String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (extension.equalsIgnoreCase("") || mimetype == null) {
            // if there is no extension or there is no definite mimetype, still try to open the file            share.setType("text*//*");
        } else {
            share.setType(mimetype);
        }
        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        context.startActivity(Intent.createChooser(share, "Share File"));

    }

}

How to use custom font in Android Studio

How to use custom font in Android Studio


  1. Go to the (project folder)
  2. Then app>src>main
  3. Create folder 'assets>fonts' into the main folder.
  4. Put your .ttf file into the fonts folder.
        AssetManager am = context.getApplicationContext().getAssets();
    
        typeface = Typeface.createFromAsset(am,
                String.format(Locale.US, "fonts/%s", "abc.ttf"));
    
        setTypeface(typeface);
    or try this way:
       TextView tx = (TextView)findViewById(R.id.textview1);
    
       Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/abc.ttf");
    
       tx.setTypeface(custom_font);

Prestige DRIP PCMD 3.0 6 Cups Coffee Maker  (Black)

Prestige DRIP PCMD 3.0 6 Cups Coffee Maker (Black)

Prestige DRIP PCMD 3.0 6 Cups Coffee Maker  (Black)



Rs. ₹1,140
Price ₹1,295 11% off


Shopping Now:- http://fkrt.it/H0I2SnuuuN

Highlights
  • Type: Filter Coffee Maker
  • Capacity: 6 Cups
  • Water Level Indicator
  • Power Consumption: 650 W
Services
  • 1 YEAR
  • 10 Days Replacement Policy
    ?
  • Cash on Delivery available
    ?
Description
Let your coffee come alive with great aroma and rich taste. Mesmerize yourself and your guests with that great cup of coffee. Prestige Drip Coffee maker - for those who love authentic South Indian filter coffee. Making great tasting filter coffee is now easy with Prestige Drip Coffee Maker. Advance Design Filter- The advance design mesh filter faciliates thick decoration for the authentic taste of South Indian filter coffee. Translucent Water Gauge - To check Water level with opening the coffee maker. Brew Basket with Lifter Handle - The brew basket with lifter handle facilitates easy removal of filter. Glass carafe - Elegant glass carafe collects filtered coffee decoction. Anti Drip valve- The filter's anti-drip valve prevents dripping when the carafe is removed. Steam vent - Releasing excess steam so that there is no pressure inside the appliance thereby ensuring safety
Read More