Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9528] Android: Saved Camera images are not getting stored on sdcard but the internal storage

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-06-16T00:07:42.000+0000
Affected Version/sRelease 2.0.2
Fix Version/sn/a
ComponentsAndroid
LabelsRegression, core
ReporterVarun Joshi
AssigneeOpie Cyrus
Created2012-06-13T17:10:52.000+0000
Updated2017-03-31T17:17:43.000+0000

Description

Problem

Cannot Save the images taken by camera on the external directory by this method: Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, 'PlayGroundPhotos'); The sample code is here: {noformat} var win = Titanium.UI.createWindow({ backgroundColor:'white' }); Titanium.Media.showCamera({ success:function(event) { var cropRect = event.cropRect; var image = event.media; Ti.API.debug('Our type was: '+event.mediaType); if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { /******** capture image in a imageView ********/ var imageView = Ti.UI.createImageView({ width:win.width, height:win.height, image:event.media }); win.add(imageView); /******** rotate the imageView ************/ var transformCurrentPicture = Titanium.UI.create2DMatrix(); imageView.addEventListener('click',function(e){ transformCurrentPicture = transformCurrentPicture.rotate(90); imageView.animate({transform:transformCurrentPicture}); savePhoto('Hello.png',imageView.toBlob()); }); // savePhoto('Hello',imageView.toBlob()); } else { alert("got the wrong type back ="+event.mediaType); } }, cancel:function() { }, error:function(error) { // create alert var a = Titanium.UI.createAlertDialog({title:'Camera'}); // set message if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Please run this test on device'); } else { a.setMessage('Unexpected error: ' + error.code); } // show alert a.show(); }, saveToPhotoGallery:true, allowEditing:true, mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO] }); win.open(); /******* function to save the image **********/ function savePhoto(photoName,photoToSave){ var photoPath = ''; var photoDir = ''; //Check for photo dir and create if not there if (Titanium.Filesystem.isExternalStoragePresent()){ photoDir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, 'PlayGroundPhotos'); if ( ! photoDir.exists()){ photoDir.createDirectory(); } } //check for photo dir and create if not there locally since no external storage else{ photoDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'PlayGroundPhotos'); if ( ! photoDir.exists()) { photoDir.createDirectory(); } else{ alert('photoDir exists'); } } //At this point we know if SD card exists and have created photo directory if needed photoPath = photoDir.nativePath; alert('The photopath is: '+photoPath); var f = Titanium.Filesystem.getFile(photoPath,photoName); f.write(photoToSave); } {noformat} The above code saves the image in internal phone storage even when sdcard is present on the phone. Tested with HTC Sensation 4G, Motorola Atrix (2.3.3 Android OS) *NOTE: Running the above code in 1.8.2 SDK saves it in the correct location (external storage)*

Comments

  1. Opie Cyrus 2012-06-16

    Was unable to reproduce the fail case against master on Droid 2 2.3.4. Verified that images are saved to sdcard.
  2. Lee Morris 2017-03-31

    Closing ticket as I am unable to reproduce the issue using the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80

JSON Source