I have developing app which get the path from SDcard for all types (Images, Audio, Video)... It works fine for opening the Default Android Browsers(Gallery). But when i open the SDcard in other app's it throws NullPointer. For example i have open the SDcard through my app using Explorer app shows null pointer exception... I will save the image path to SQlite and get the content from the SQLite on another activity. But this Explorer app shows all types, not only for specified type. (Example i select image button, but it shows all types).
radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup rd_group, int checked_id) {
checking = null;
switch(checked_id) {
case R.id.radio_image:
checking = "image";
break;
case R.id.radio_audio:
checking = "audio";
break;
case R.id.radio_video:
checking = "video";
break;
}
}
});
// I have a radio button for type of content will shown only
select_content.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if(checking.equals("")) {
Toast.makeText(getApplicationContext(), "Please select the content type", Toast.LENGTH_SHORT).show();
return;
}
// when i select image, show image content only in SDcard.
// When i select audio, show only audio contents.
// when i select video, show only video contents.
if(checking.equals("image")) {
Intent intent_image = new Intent();
intent_image.setType("image/*");
intent_image.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent_image, "Select Image"), SELECT_IMAGE_DIALOG);
}
if(checking.equals("audio")) {
Intent intent_audio = new Intent();
intent_audio.setType("audio/*");
intent_audio.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent_audio, "Select Audio"), SELECT_AUDIO_DIALOG);
}
if(checking.equals("video")) {
Intent intent_video = new Intent();
intent_video.setType("video/*");
intent_video.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent_video, "Select Video"), SELECT_VIDEO_DIALOG);
}
}
});
public void onActivityResult(int requestCode, int resultCode, Intent result) {
// imagePath = null;
if (requestCode == SELECT_IMAGE_DIALOG) {
if (resultCode == Activity.RESULT_OK) {
Uri data = result.getData();
Log.d("DATA", data.toString());
selected_Path = getPath(data);
final_path.getBytes();
selected_path_text.setText(final_path);
Log.d("Image Path", final_path);
}
}
if (requestCode == SELECT_AUDIO_DIALOG) {
if (resultCode == RESULT_OK) {
Uri data = result.getData();
Log.d("DATA", data.toString());
selected_Path = getPath(data);
final_path.getBytes();
selected_path_text.setText(final_path);
Log.d("Audio Path", final_path);
}
}
if (requestCode == SELECT_VIDEO_DIALOG) {
if (resultCode == RESULT_OK) {
Uri data = result.getData();
Log.d("DATA", data.toString());
selected_Path = getPath(data);
final_path.getBytes();
selected_path_text.setText(final_path);
Log.d("Video Path", final_path);
}
}
}
private String getPath(Uri data) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(data, projection, null, null, null);
column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
final_path = cursor.getString(column_index);
Log.d("Image Path", final_path);
return cursor.getString(column_index);
}