一部のアプリケーション(Googleドライブ、ドロップボックスなど)からAndroidアプリケーションにpdf、docファイルを共有したいと思います。
私が試したこと
これらのコード スニペットを使用してアプリケーションで画像を共有できます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 を取得できますかこれらのファイルをアプリケーションで共有した場合のファイル パス。