Commit a43b21a9 authored by Schoumi's avatar Schoumi

Allow multi pick from gallery on android api >= 18

parent 94856dcf
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment