1

In my application there is a button, that, when pressed, is supposed to open either the picture gallery, or the video gallery, or the audioplayer.

Please how would I construct an intent to perform that?

Piyush
  • 18,895
  • 5
  • 32
  • 63
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157

2 Answers2

1

Try with this just onclick of any button pass the file path and then this method poen any type of file according to that file

 File file = new File(filePath); 
    MimeTypeMap map = MimeTypeMap.getSingleton();
       String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
         String type = map.getMimeTypeFromExtension(ext);
        if (type == null)
        type = "*/*";

    Uri uri = Uri.parse("www.google.com");
    Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
    Uri data = Uri.fromFile(file);
    type_intent.setDataAndType(data, type);
    startActivity(type_intent);

For images

private void getallimages(File dir)
    {

    String[] STAR = { "*" };
    controller.images.clear();

    final String orderBy = MediaStore.Images.Media.DEFAULT_SORT_ORDER;
    Cursor imagecursor = cntx.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, STAR, null, null, orderBy);
    int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
    int count = imagecursor.getCount();
    for (int i = 0; i < count; i++) {
        imagecursor.moveToPosition(i);
        int id = imagecursor.getInt(image_column_index);
        ImageItem imageItem = new ImageItem();//this is my wrapper class 
        if(new File(imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA))).length()<=10485760)
        {
            imageItem.filePath = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA));

        imageItem.id = id;
        imageItem.selection = false; //newly added item will be selected by default this it do for check box unselect u dont need to fill this 
        controller.images.add(imageItem);//this i just add all info in wrapper class    

        }

} }

for audio

private void getallaudio()
{
     String[] STAR = { "*" };
    controller.audioWrapper.clear();
    Cursor audioCursor = cntx.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null);
    if (audioCursor != null) 
    {
        if (audioCursor.moveToFirst()) 
        {
            do 
            {

                String path = audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DATA));


                           controller.audioWrapper.add(new MediaWrapper(new File(path).getName(), path, "Audio",false));



             }while (audioCursor.moveToNext());

        }
     }


}

and for video

private void getallvideo()
    {
         String[] STAR = { "*" };

        controller.videoWrapper.clear();
        Cursor videoCursor = cntx.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null);

        if (videoCursor != null) 
        {
            if (videoCursor.moveToFirst()) 
            {
                do 
                {


                    String path = videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Images.Media.DATA));

                               controller.videoWrapper.add(new MediaWrapper(new File(path).getName(), path, "Video",false,color_string));




                 }while (videoCursor.moveToNext());

            }
         }
    }
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
  • thank you Bhanu, but I do not need to open a single file, rather I need the user to see the Gallery and MediaPlayer apps so that he can choose what to use, either audio, video or pictures. – Lisa Anne Mar 14 '14 at 09:53
  • now see my bigg bigg biggg ans :) it will give u all u want @LisaAnne :) – Bhanu Sharma Mar 14 '14 at 10:05
0

I would realize it this way:
On Button click, pop up a custom dialog box with 3 buttons.

  1. picture gallery button
  2. video gallery button
  3. audio player button

Depending on user selection, you start the intent which corresponds to the action.

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103