Maybe use a counter and, if the file exists, increment it?
On Wednesday, November 28, 2012 3:25:55 PM UTC-6, Ricardo Cardoso wrote: > > I forgot to write the variables in the code that put the fullpath > > public final static String APP_PATH_SD_CARD = "/directory/"; > > But how not to use the "System.currentTimeMillis ()"? > > > Without replacing the photo taken next to a picture? > > > > 2012/11/28 bob <[email protected] <javascript:>> > >> Well, the code where you set fullPath is obviously wrong. >> >> Also, be careful saving it with this file name: >> >> System.currentTimeMillis () + ". Jpg" >> >> If you construct that file name at a different time, it may not open. >> >> >> >> On Wednesday, November 28, 2012 2:31:01 PM UTC-6, Ricardo Cardoso wrote: >>> >>> I'm taking a picture with my application and saving to the phone >>> directory .... >>> But when I ask to save with this resolution in pixels is giving >>> nullpointerexeption: >>> 11-28 18:01:47.593: E / AndroidRuntime (19992): Caused by: >>> java.lang.NullPointerException >>> 11-28 18:01:47.593: E / AndroidRuntime (19992): at >>> android.graphics.Bitmap.**createScaledBitmap (Bitmap.java: 461) >>> >>> I'm doing this: >>> btn_camera.setOnClickListener (new View.OnClickListener () { >>> >>> >>> @ Override >>> >>> public void onClick (View v) { >>> >>> Intent intent = new Intent ("android.media.action.IMAGE_**CAPTURE"); >>> >>> startActivityForResult (intent, TIRA_FOTO); >>> >>> } >>> >>> }); >>> >>> >>> >>> And then I caught the activityResult >>> >>> @ Override >>> >>> protected void onActivityResult (int requestCode, int resultCode, >>> Intent data) { >>> >>> super.onActivityResult (requestCode, resultCode, data); >>> >>> if (requestCode == TIRA_FOTO && resultCode == RESULT_OK) { >>> >>> Bitmap photo = (Bitmap) data.getExtras (.) Get ("date"); >>> >>> saveImageToExternalStorage (photo); >>> >>> } Else if (resultCode == RESULT_CANCELED) { >>> >>> Toast.makeText (this, "Cancelled", Toast.LENGTH_SHORT.) Show (); >>> >>> Else {} >>> >>> Toast.makeText (this, "Left", Toast.LENGTH_SHORT.) Show (); >>> >>> } >>> >>> } >>> >>> >>> >>> The function to save the image: >>> >>> >>> >>> public boolean saveImageToExternalStorage (Bitmap image) { >>> >>> >>> >>> Environment.**getExternalStorageDirectory fullpath = (). >>> getAbsolutePath () + APP_PATH_SD_CARD; >>> >>> >>> >>> / / Image = BitmapFactory.decodeFile (FullPath); >>> >>> / / Image = Bitmap.createScaledBitmap (image, 320, 426, true); >>> >>> try { >>> >>> File dir = new File (FullPath); >>> >>> if (! dir.exists ()) { >>> >>> dir.mkdirs (); >>> >>> } >>> >>> >>> >>> OutputStream fout = null; >>> >>> File file = new File (fullpath, System.currentTimeMillis () + ". >>> Jpg"); >>> >>> file.createNewFile (); >>> >>> fout = new FileOutputStream (file); >>> >>> >>> >>> / / 100 means the compression, the lower you go, the stronger the >>> compression >>> >>> image.compress (Bitmap.CompressFormat.JPEG, 100, fout); >>> >>> >>> >>> fOut.flush (); >>> >>> fOut.close (); >>> >>> >>> >>> >>> >>> / / MediaStore.Images.Media.**insertImage (getContentResolver (), >>> file.getAbsolutePath (), file.getName (), file.getName ()); >>> >>> return true; >>> >>> >>> >>> } Catch (Exception e) { >>> >>> Log.e ("saveToExternalStorage ()", e.getMessage ()); >>> >>> return false; >>> >>> } >>> >>> } >>> >>> >>> If I uncomment these lines >>> / / Image = BitmapFactory.decodeFile (FullPath); >>> >>> / / Image = Bitmap.createScaledBitmap (image, 320, 426, true); >>> >>> From the nullpointer error, the problem is that you are saving with >>> 121x162 resolution and is getting very bad image ... >>> >>> Can anyone help me?? >>> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to >> [email protected]<javascript:> >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

