This technique is successfully performed for using pictures from Gallery But i want to implement the same thing for Audio as well as video . The code is
public void video(View v)
{
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
RESULT_LOAD_VIDEO = 1;
startActivityForResult(i, RESULT_LOAD_VIDEO);
}
public void audio(View v)
{
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
RESULT_LOAD_AUDIO = 1;
startActivityForResult(i, RESULT_LOAD_AUDIO);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK &&null != data)
{
Uri selectedImage = data.getData(); String[]
filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex); cursor.close();
// String picturePath contains the path of selected Image
NewPoll.flag++;
Path.patha= picturePath;
Intent ints=new Intent(getApplicationContext(),NewPoll.class);
ints.putExtra("address",picturePath);
ints.putExtra("option",comingData);
startActivity(ints);
}
if (requestCode == RESULT_LOAD_VIDEO && resultCode == RESULT_OK &&null != data)
{
Uri selectedVideo= data.getData(); String[]
filePathColumn = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(selectedVideo,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String videoPath = cursor.getString(columnIndex); cursor.close();
// String picturePath contains the path of selected Image
NewPoll.flag++;
Path.patha= videoPath;
Intent ints=new Intent(getApplicationContext(),NewPoll.class);
ints.putExtra("address",videoPath);
ints.putExtra("option",comingData);
startActivity(ints);
}
if (requestCode == RESULT_LOAD_AUDIO && resultCode == RESULT_OK &&null != data)
{
Uri selectedAudio= data.getData(); String[]
filePathColumn = { MediaStore.Audio.Media.DATA };
Cursor cursor = getContentResolver().query(selectedAudio,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String audioPath = cursor.getString(columnIndex); cursor.close();
// String picturePath contains the path of selected Image
NewPoll.flag++;
Path.patha= audioPath;
Intent ints=new Intent(getApplicationContext(),NewPoll.class);
ints.putExtra("address",audioPath);
ints.putExtra("option",comingData);
startActivity(ints);
}
}
I got success for photo-gallery but dont know how to use video and audio gallery Code from ur side is appriciated ! Thanks