[英]Getting both Photos and Videos from the new Google Photos app on Android
我希望用戶將一堆視頻/照片導入我的應用程序。 這是我之前使用的代碼:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("image/*,video/*");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
我遇到的問題是,上面只返回來自新Google照片應用的照片。 如果我僅將數據類型更改為“video / *”,則“照片”應用會返回視頻。 這適用於KitKat +
編輯:
我嘗試過以下代碼 - 它適用於某些畫廊但不適用於大多數而非Google照片:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (AndroidHelper.isKitKatAndAbove()) {
Log.d(TAG, "Pick from gallery (KitKat+)");
String[] mimeTypes = {"image/*", "video/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
} else {
Log.d(TAG, "Pick from gallery (Compatibility)");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
}
這就是我最終做的事情:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
if (AndroidHelper.isKitKatAndAbove()) {
Log.d(TAG, "Pick from gallery (KitKat+)");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
} else {
Log.d(TAG, "Pick from gallery (Compatibility)");
activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
}
然后,當我得到結果時,我檢查文件的類型。 似乎工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.