Question

Is there any way to do this Is possible not allow user access the specify folder? was created by me,

Actually After downloaded images from URL. I want store some images into this folder,

But I not want allow user can go there.

People who know please help me,

Thanks,

Was it helpful?

Solution

You can store file in internal storage like this

try {
    URL url = new URL(strUrl);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream is = conn.getInputStream();
    Bitmap bm = BitmapFactory.decodeStream(is);
    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    File file = new File(directory, System.currentTimeMillis() + ".png");
    FileOutputStream fos = openFileOutput(file.getAbsolutePath(), Context.MODE_PRIVATE);

    ByteArrayOutputStream outstream = new ByteArrayOutputStream();

    bm.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
    byte[] byteArray = outstream.toByteArray();

    fos.write(byteArray);
    fos.close();

} catch (Exception e) {

}

OTHER TIPS

you can store files in the internal storage. This storage is private by default. Files stored on the external SD-Card cannot be made private.

Internal Storage

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.

External Storage

Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

You can't prevent a user to access any file in linux system. They can root access any file. What you can do is to store the file encrypted so that even when they access, they can't see your image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top