android: save images to specific folder in the sd card

后端 未结 3 1874
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 22:09

i have here a code snippet that saves a bitmap on sd card:

String filename = String.valueOf(System.currentTimeMillis()) ;
ContentValues values = new ContentV         


        
3条回答
  •  既然无缘
    2021-01-15 22:35

    try this

    File myDir=new File("/sdcard/saved_images");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-"+ n +".jpg";
    File 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();
    }
    

    and add this in manifest

     
    

    check my answer here : https://stackoverflow.com/a/7887114/964741

提交回复
热议问题