I'm using following method to call pick any file but it doesn't work properly.
private void fileIntent(int file)
{
if ((ActivityCompat.checkSelfPermission(ICShowFileCabinetDetails.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, file);
} else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Select File"), file);
}
}
Following permissions are set in manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
OnActivtyresult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SELECT_FILE && data != null) {
try {
mProPic = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
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);
// String filename = selectedImage.getLastPathSegment();
String[] filenames = picturePath.split("\\/");
int count = filenames.length;
String name = filenames[count - 1];
imagepickerselected = 1;
UploadIamgeinServer(1, name);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Choose file getting open whenever i click to choose file in button click. But all files are shown like hidden except images, Click doest work. Without method in it button click works fine. If anyone found errors in code please let me know.
Thanks
else
– Cataplasm