I need to create a view to select a photo and store that photo in my local db.
I have tried:
private final int SELECT_IMAGE = 1;
In a button I put:
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_IMAGE);
But when I select the picture, the intent close and dont return to my apk.
Some here, my intent is finish. And the onActivityResult
never runs. So, i can't handler...
My onActivityResult
is this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case SELECT_IMAGE:
if(resultCode==RESULT_OK){
Uri uri = data.getData();
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if(cursor.moveToFirst()){
int columnIndex = cursor.getColumnIndex(projection[0]);
String filePath = cursor.getString(columnIndex);
}
cursor.close();
}
}
}
And to help, on LogCat I have NOTHING. Amazing...
I am using apk on API 7.