ANDROID:BITMAP IMAGE STORE IN EXTERNAL OR INTERNAL STORAGE?

Write this line in onCreate() method, This line of code is used for checking Sd card  is available or not.


  1. Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals
                             (android.os.Environment.MEDIA_MOUNTED);

And this method is used for save your bitmap file in external and internal storage.

  1. private String SaveImage_Sta(Bitmap finalBitmap, String name) {
    if(isSDPresent) {
    Log.i("isSDPresent yes", " path is==> " +isSDPresent );
    String root = Environment.getExternalStorageDirectory().toString() + "/profile";
    File myDir = new File(root);
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = name + ".jpg";
    file = new File(myDir, fname);
    if (file.exists())
    file.delete();
    try {
    FileOutputStream out = new FileOutputStream(file);
    finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
    out.flush();
    out.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
        } else {
        
         Log.i("isSDPresent no ", " path is==> false ");
         ContextWrapper cw = new ContextWrapper(getApplicationContext());
             // path to /data/data/yourapp/app_data/imageDir
            File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
            // Create imageDir
            file =new File(directory,"profile.jpg");       
          
            if (file.exists())
    file.delete();
            try {        
             FileOutputStream fos = new FileOutputStream(file);
             finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
             fos.flush();
                fos.close();
            
            } catch (Exception e) {
                e.printStackTrace();
            }       
        }
    return file.toString();


No comments:

Select DateRange UsingRangePicker.

  /* * This Method is for select range from picker. * */ private fun selectDateRangeUsingRangePicker () { pageNumber = 1 val displ...