Retrieve File Name Of Content From Other Apps
I have registered my app to receive files (of any type, not just images) from other apps following this post. I have implemented the solution that was answered but I cannot find a
Solution 1:
In MOST cases this will solve your problem:
Uri intentData = intent.getData();
if (intentData != null) {
String filePath;
if("content".equals(intent.getScheme()))
{
filePath = getFilePathFromContentUri(intentData);
}
else
{
filePath = intentData.getPath();
}
}
privateStringgetFilePathFromContentUri(Uri selectedUri) {
String filePath;
String[] filePathColumn = {MediaColumns.DATA};
Cursor cursor = getContentResolver().query(selectedUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
cursor.close();
return filePath;
}
Solution 2:
Is there a way to retrieve it?
Generally, no, because there may not be a name, in part because there may not be a file. You may be able to get an InputStream
on the contents, but that does not mean that there is a file behind the InputStream
.
There may be some specific hacks for some specific providers (e.g., MediaStore
) to try to determine the file name associated with some data Uri
, though such hacks may not be reliable.
Solution 3:
onCreate()
Intent intent1 = getIntent();
String action = intent1.getAction();
Stringtype = intent1.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
this.handleSend(intent1);
}
voidhandleSend(Intent intent) {
try {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
imageShare.setImageURI(imageUri);
} catch (Exception e) {
e.printStackTrace();
}
}
Post a Comment for "Retrieve File Name Of Content From Other Apps"