Browse Source

Allow multi pick from gallery on android api >= 18

tags/release-v2.3
Schoumi 2 years ago
parent
commit
a43b21a99b
1 changed files with 18 additions and 4 deletions
  1. 18
    4
      app/src/main/java/fr/mobdev/goblim/activity/UploadActivity.java

+ 18
- 4
app/src/main/java/fr/mobdev/goblim/activity/UploadActivity.java View File

@@ -19,6 +19,7 @@
package fr.mobdev.goblim.activity;

import android.app.ProgressDialog;
import android.content.ClipData;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -26,6 +27,7 @@ import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.OpenableColumns;
import android.support.v7.app.AlertDialog;
@@ -512,6 +514,8 @@ public class UploadActivity extends AppCompatActivity {
//ask for image file
Intent requestFileIntent = new Intent(Intent.ACTION_PICK);
requestFileIntent.setType("image/*");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
requestFileIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
startActivityForResult(requestFileIntent, 0);

}
@@ -520,10 +524,20 @@ public class UploadActivity extends AppCompatActivity {
public void onActivityResult(int requestCode, int resultCode,Intent returnIntent) {
if(resultCode == RESULT_OK){
//retrieve uri from the request image activity and prepare
Uri imageUri = returnIntent.getData();
uris.add(imageUri);
updateSpanCount();
adapter.addUri(this,imageUri);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
Uri imageUri = returnIntent.getData();
uris.add(imageUri);
updateSpanCount();
adapter.addUri(this,imageUri);
} else {
ClipData clip = returnIntent.getClipData();
for(int i = 0; i < clip.getItemCount(); i++) {
Uri imageUri = clip.getItemAt(i).getUri();
uris.add(imageUri);
updateSpanCount();
adapter.addUri(this,imageUri);
}
}

Button uploadBt = (Button) findViewById(R.id.upload_button);
uploadBt.setEnabled(false);

Loading…
Cancel
Save