-1

I know the Camera plugin gives access to select a photo from the camera roll but I need the app to select a random photo - not sure if this is possible.

I'd need this to work in iOS and Android.

blancos
  • 1,576
  • 2
  • 16
  • 38
MarkL
  • 109
  • 1
  • 14
  • What do you mean by selecting a random photo? Explain the problem clearly. – blancos Apr 23 '15 at 09:16
  • not sure how else to explain, the app will have a function that selects a random photo in the camera roll that will then be uploaded to a database. – MarkL Apr 23 '15 at 09:21
  • So what is the problem exactly? You want to know how to select photos or how to select them randomly? – blancos Apr 23 '15 at 09:23
  • Yeah the random part, I know the plugin will give me access to the camera roll to select a photo and give me access to the camera to take a photo. But what I actually need to know is can I somehow get a random photo so the user doesn't pick one. I know it sounds odd - but its something a client has asked and im not sure if its possible. – MarkL Apr 23 '15 at 09:27

1 Answers1

1

I am still confused about your requirement but I will just try to answer. My answer is with respect to Objective-c; same can be extended to android.

Since you said that you have access to camera roll, take all the names of the files and put them into NSArray. Suppose total number of photos are N. Use any randomise method (like arc4random_uniform(N)) to get a random number between 0 and N. Use that number as index of your NSArray and upload the photo whose name is there at that index.

UPDATE: To get filenames using phonegap you can check out this link. It is about svg files, you can do the same for your image format(png, jpeg etc)

Community
  • 1
  • 1
blancos
  • 1,576
  • 2
  • 16
  • 38
  • Thanks, and yeah this is how I would probably deal with getting the random photo. The issue with this is getting the initial list of photos... maybe that's what my question should be. 'Is it possible to get the list of photos using phonegap' – MarkL Apr 23 '15 at 09:43