Search code examples
androidandroid-camerafilepickerandroid-file

Select a picture and upload android


Here is the problem...

I'm trying to create an app that allows you to upload an image or sound recording to a database along with some information, The upload part isn't a problem, what I would like to do is have 3 options, take a photo, record a sound and select a file. I decided to tackle select a file first... Is it possible to be able to simply click a button which allows you to select a file then post that to my php script? and pointers on how to start the camera or sound recorder would also be appreciated greatly

Thanks

James


Solution

  • You could use a Dialog with a ListView for selecting your file. Once you've selected the file, you could check out this tutorial for uploading it to your web service:

    http://www.anddev.org/upload_files_to_web_server-t443-s30.html

    You can use an intent to start the camera:

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, 1);
    

    Which you can capture in:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
      // result code = 1
      // grab the image you took with the camera from data
    }
    

    * Update *

    Regarding the dialog, you could check out these links for more information on it's creation:

    is it possible to create listview inside dialog?

    http://androidforums.com/application-development/53924-how-add-listview-dialog.html

    Also you'll probably need to familiarize yourself with the ArrayAdapter for managing your ListView.

    http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/