I integrate file picker in my application. so i set below code for that and i use this library for that. library
public class FileChooserExampleActivity extends Activity {
private static final String TAG = "FileChooserExampleActivity";
private static final int REQUEST_CODE = 6384;
private static final int REQUEST_WRITE_STORAGE = 112;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a simple button to start the file chooser process
Button button = new Button(this);
button.setText(R.string.choose_file);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Display the file chooser dialog
showChooser();
}
});
setContentView(button);
}
private void showChooser() {
// Use the GET_CONTENT intent from the utility class
Intent target = FileUtils.createGetContentIntent();
// Create the chooser Intent
Intent intent = Intent.createChooser(
target, getString(R.string.chooser_title));
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// The reason for the existence of aFileChooser
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE:
// If the file selection was successful
if (resultCode == RESULT_OK) {
if (data != null) {
// Get the URI of the selected file
final Uri uri = data.getData();
Log.i(TAG, "Uri = " + uri.toString());
try {
// Get the file path from the URI
final String path = FileUtils.getPath(this, uri);
Toast.makeText(FileChooserExampleActivity.this,
"File Selected: " + path, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("FileSelectorTestActivity", "File select error", e);
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
permissin:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
When i run above code in Android Marshmallow 6.0 device and i fetch image from sdcard than i get selected file path value as null so any idea how can i solve this ? your all suggestions are appreciable