I hope you can help me with my simple problem. I am trying to select an image to display on my Imageview from my gallery, It works but the thing is, It disappears after I close my app. Please check the code that I found below.
iv=(ImageView) rootView.findViewById(R.id.profpic);
iv.setOnClickListener(this);
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(getActivity(), "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
iv.setImageURI(uri);
Log.d(TAG, "File Uri: " + uri.toString());
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
and my xml:
<ImageView
android:id="@+id/profpic"
android:layout_width="113dp"
android:layout_height="113dp"
android:paddingRight="1dp"
android:src="@drawable/propic" />
I am new to android development and any help will be appreciated. Thanks in advance!