Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>private void savePhoto(String fileName, final String extension) { // First, get all the file names from the directory String[] allFiles = new File(Environment.getExternalStorageDirectory().toString()).list(); // Create a new empty list to put all the matching file names in // In this case all the files names that are "photo.jpg" or "photo#.jpg" ArrayList&lt;String&gt; files = new ArrayList&lt;String&gt;(); // Skim through all the files for(String file : allFiles) { // Use a regular expression to find matching files // fileName[0-9]+\.extension|fileName\.extension if(file.matches(fileName + "[0-9]+\\." + extension + "|" + fileName + "\\." + extension)) { files.add(file); } } files.trimToSize(); // Now sift through the list and find out what the highest number is // Example, if you've taken 8 photos, then highestNumber will equal 8 int highestNumber = 0; int digit; for(String file : files) { try { digit = Integer.parseInt(file.replace(fileName, "").replace("." + extension, "")); } catch(NumberFormatException e) { digit = 1; } if(digit &gt; highestNumber) { highestNumber = digit; } } // Create the file object fileName = fileName + highestNumber++ + "." + extension; File file = new File(Environment.getExternalStorageDirectory().toString(), fileName); // In not sure what you do around here, I can't find any array titled "jpeg" // So do what you will FileOutputStream fostream = null; try { fostream = new FileOutputStream(file); //MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle, yourDescription); //write jpeg to local drive fostream.write(jpeg[0]); } catch(IOException e) { e.printStackTrace(); } finally { if(fostream != null) { try { fostream.flush(); fostream.close(); } catch(IOException e) { e.printStackTrace(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload