I have made an app uploading pictures to server.
I succeed in just accessing to my basic gallery app after clicking the button
but after going to my basic gallery app , I want to choose my pictures(more than one) and make my own button to control(uploading or sending) them.
In android instagram, it controls like it!
But when accessing gallery app, this activity is not made by me, so I don't know how to control to get and send data.
What I done (helped by stack overflow) so far is below:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Intent.createChooser"), SELECT_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Toast.makeText(this, "onActivityResult 실행", Toast.LENGTH_LONG).show();
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
But this code works, after accessing gallery app, when I select pictures, app is gone!
create an array of string String[] imagUrls=new String[n] to add image urls every time and insted of img.setImageURI(selectedImageUri); do like imageUrls[0]=selectedImageUri,imageUrls[0]=selectedImageUri ... and finally upload all images from the array.