[SOLVED] media.selectPhoto() not working on Android

Corona SDK 2013.2100
Android 2.3.6 and 4.4

When I try to select a photo using media.selectPhoto nothing is selected and the following gets logged the device log:

D/MediaPlayer(10871): at com.ansca.corona.CoronaActivity.getDurationOfVideo(CoronaActivity.java:1188)
D/MediaPlayer(10871): at com.ansca.corona.CoronaActivity.access$200(CoronaActivity.java:22)
D/MediaPlayer(10871): at com.ansca.corona.CoronaActivity$SelectMediaActivityResultHandler$1.run(CoronaActivity.java:1379)
I/Corona (10871): Runtime error
I/Corona (10871): ?:0: attempt to index a nil value
I/Corona (10871): stack traceback:
I/Corona (10871): [C]: ?
I/Corona (10871): ?: in function ‘?’
I/Corona (10871): ?: in function <?:66>
I/Corona (10871): Runtime error
I/Corona (10871):
I/Corona (10871): stack traceback:
I/Corona (10871): [C]: ?
I/Corona (10871): ?: in function ‘?’
I/Corona (10871): ?: in function <?:66>

The statement I’m using is the following (works fine on iOS devices):

media.selectPhoto{ mediaSource = media.PhotoLibrary, origin = picker.contentBounds, destination = {baseDir=system.TemporaryDirectory, filename=imageName, type="image"}, listener = function(event) if (event.completed) then print("selected") end end}

I ran your code snippet on a Samsung Galaxy Tab2 with build 2100 and it works fine. I had to recreate the project to test. I also tested the sample code on the media.showPhoto API page. 

Need a bug report with details and a test project to validate the issue.

OK… Sorry for what seems to be a false alarm.

I was able to run the sample code on the media.selectPhoto() API page.

I must have some weird thing going on in my code. I’ll double-check to see what’s going on…

I’ve found the problem. There is a bug.

For some reason Corona doesn’t write anything to system.TemporaryDirectory on Android.

No error is given until you try to read the file since no file exists.

Changing to system.DocumentsDirectory or system.CachesDirectory writes the file to their respective directories.

I have the “android.permission.WRITE_EXTERNAL_STORAGE” permission set.

I’ll submit a bug report.

Okaaaay… This is getting weird.

TemporaryDirectory works in the sample app I created, but in my app it doesn’t work.

However DocumentsDirectory and CachesDirectory *does* work in my app…

It was my fault.  :unsure:

To prevent file clutter, I have a routine that clears out the Temporary directory on app start and resume.

The thing is that Android suspends the app when showing the photo picker, and then resumes when a photo is selected.

My routine effectively removed the selected image before it could be loaded resulting is the behavior I was seeing. D’oh!

I’ve modified my routine to only remove files from the Temporary directory if a certain amount of time has passed.

It’s now working perfectly on Android  ;).

I ran your code snippet on a Samsung Galaxy Tab2 with build 2100 and it works fine. I had to recreate the project to test. I also tested the sample code on the media.showPhoto API page. 

Need a bug report with details and a test project to validate the issue.

OK… Sorry for what seems to be a false alarm.

I was able to run the sample code on the media.selectPhoto() API page.

I must have some weird thing going on in my code. I’ll double-check to see what’s going on…

I’ve found the problem. There is a bug.

For some reason Corona doesn’t write anything to system.TemporaryDirectory on Android.

No error is given until you try to read the file since no file exists.

Changing to system.DocumentsDirectory or system.CachesDirectory writes the file to their respective directories.

I have the “android.permission.WRITE_EXTERNAL_STORAGE” permission set.

I’ll submit a bug report.

Okaaaay… This is getting weird.

TemporaryDirectory works in the sample app I created, but in my app it doesn’t work.

However DocumentsDirectory and CachesDirectory *does* work in my app…

It was my fault.  :unsure:

To prevent file clutter, I have a routine that clears out the Temporary directory on app start and resume.

The thing is that Android suspends the app when showing the photo picker, and then resumes when a photo is selected.

My routine effectively removed the selected image before it could be loaded resulting is the behavior I was seeing. D’oh!

I’ve modified my routine to only remove files from the Temporary directory if a certain amount of time has passed.

It’s now working perfectly on Android  ;).