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?
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?
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());
}
}
}
I would realize it this way:
On Button click, pop up a custom dialog box with 3 buttons.
Depending on user selection, you start the intent which corresponds to the action.