I would like to share pdf,doc file from some application(example google drive,dropbox) to my android application.
What I tried
I can share a image into my application using these code snippet,I can get that image path using below code in AndroidManifest.xml
.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
In my Activity
Intent myintent = getIntent();
Bundle extras = myintent.getExtras();
String action = myintent.getAction();
// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) {
// Get resource path
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
String filename = parseUriToFilename(uri);
if (filename != null) {
doing some process here//
}
}
}
public String parseUriToFilename(Uri uri) {
String selectedImagePath = null;
String filemanagerPath = uri.getPath();
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
// Here you will get a null pointer if cursor is null
// This can be if you used OI file manager for picking the media
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
selectedImagePath = cursor.getString(column_index);
}
if (selectedImagePath != null) {
return selectedImagePath;
}
else if (filemanagerPath != null) {
return filemanagerPath;
}
return null;
}
what I actually need
using above code I can get shared image path so that I can perform my task.I would like to share .pdf,.doc file into my app for that purpose I need exact location of the file.so how can I get pdf,doc file path if I shared these files into my Application.
using above code I can get shared image path so that I can perform my task
No, you can get the path to some images, those that happen to be indexed by the MediaStore
. Not all images are indexed by the MediaStore
. Not all images are stored in files at paths that your app can access.
More generally, not every content://
Uri
that you will find will be represented by a file that you can access . Instead, you will need to consume the content using the appropriate ContentResolver
methods, like openInputStream()
.
I would like to share .pdf,.doc file into my app for that purpose I need exact location of the file
For those files that happen to also be indexed by MediaStore
, you are welcome to attempt to use the same solution as you did for images indexed by MediaStore
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.