[英]How to share .pdf,.doc file into my application
I would like to share pdf,doc file from some application(example google drive,dropbox) to my android application. 我想从某些应用程序(例如Google驱动器,投递箱)共享pdf,doc文件到我的android应用程序。
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
. 我可以使用这些代码片段将图像共享到我的应用程序中,可以使用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. 使用上面的代码,我可以获得共享的图像路径,以便执行任务。为此,我想将.pdf,.doc文件共享到我的应用程序中,我需要文件的确切位置。所以我如何获取pdf,doc文件路径(如果我将这些文件共享到我的应用程序中)。
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
. 不,您可以获取一些图像的路径,这些图像恰好由MediaStore
索引了。 Not all images are indexed by the MediaStore
. 并非所有图像都由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 . 更一般而言, 并不是您将找到的每个content://
Uri
都由您可以访问的文件表示 。 Instead, you will need to consume the content using the appropriate ContentResolver
methods, like openInputStream()
. 相反,您将需要使用适当的ContentResolver
方法(如openInputStream()
来消耗内容。
I would like to share .pdf,.doc file into my app for that purpose I need exact location of the file 为此,我想将.pdf,.doc文件共享到我的应用中,我需要文件的确切位置
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
. 对于碰巧也被MediaStore
索引的那些文件,欢迎您尝试使用与MediaStore
索引的图像相同的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.