1
正如你可能已經注意到較新的Android版本,Android現在有2個圖像畫廊:畫廊和照片。未來,Google會棄用並刪除該圖庫,並且只能擁有照片庫。限制從Android照片的上傳而不是畫廊
我想讓用戶能夠使用Android API級別18+「.ExtraExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);」來上傳多個圖片進行上傳。問題是,如果用戶選擇從圖庫上傳,功能不起作用(只有一張圖片可供選擇)。
如何確保應用程序自動嘗試通過Android Photo的應用上傳?
這是我到目前爲止的代碼:
galerijButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
if(Build.VERSION.SDK_INT >= 18){
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});
..
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
if(imageReturnedIntent.getData() != null){
//If uploaded with Android Gallery (max 1 image)
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
photos.add(yourSelectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
//If uploaded with the new Android Photos gallery
ClipData clipData = imageReturnedIntent.getClipData();
for(int i = 0; i < clipData.getItemCount(); i++){
clipData.getItemAt(i);
// more code logic
}
}
}
break;
我必須在android清單中執行此操作嗎?或者給Intent對象一個標誌或什麼? –
改爲意圖photoPickerIntent = new Intent(Intent.ACTION_PICK);嘗試意圖photoPickerIntent =新意圖(com.google.exactnameofphotoapp.neededaction)。此操作包含在清單應用程序中,而不是在您的應用程序中調用。 –
我在哪裏可以找到確切的名字? –