为图像创建应用程序文件夹

时间:2017-12-22 23:46:18

标签: java android file

每当我保存图片时,都会转到/storage/emulated/0/tracker/imgname.jpg,但我想将其保存在/storage/emulated/tracker/imgname.jpg

Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());
    File dir = new File(Environment.getExternalStorageDirectory() + "/Tracker");
    dir.mkdir();
    File file = new File (dir, "img" + System.currentTimeMillis() + ".jpg");

    try {
        FileOutputStream out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(uri);
    context.sendBroadcast(mediaScanIntent);

0 个答案:

没有答案