【发布时间】:2014-07-05 14:34:02
【问题描述】:
我想将某些应用程序(例如 google drive、dropbox)中的 pdf、doc 文件共享到我的 android 应用程序。
我尝试了什么
我可以使用这些代码 sn-p 将图像共享到我的应用程序中,我可以使用 AndroidManifest.xml 中的以下代码获取该图像路径。
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
在我的活动中
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;
}
我真正需要的东西
使用上面的代码,我可以获得共享图像路径,以便我可以执行我的任务。为此,我想将 .pdf、.doc 文件共享到我的应用程序中,我需要文件的确切位置。所以我该如何获取pdf,doc 文件路径,如果我将这些文件共享到我的应用程序中。
【问题讨论】:
标签: android pdf android-intent android-manifest android-sharing