Reputation: 41
I am trying to upload image file to php server. I created a button which intents to all the images folder
Intent image = new Intent ();
image.setAction (Intent.ACTION_GET_CONTENT);
image.addCategory (Intent.CATEGORY_OPENABLE);
image.setType ("image/*");
startActivityForResult (Intent.createChooser (image, "SELECT image"), 1);
The problem is that the image file only uploads when selected from gallery folder. It only see images selected from gallery folder as valid file. I want the application to be able to upload from any image folder like images folder, downloads folder, photos folder etc.
Upvotes: 3
Views: 507
Reputation: 4788
When you startActivityForResult(intent) you have to get its result after starting that like this
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,getResources().getString(R.string.selectPic)), PICK_IMAGE);
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) {
if (data == null) {
//Display an error
return;
}
InputStream inputStream = this.getContentResolver().openInputStream(data.getData());
}
now you have an inputStream from your selected image next step is to getting its bytes and create a bitmap of that.
good luck !
Upvotes: 1