The android image viewer action open document tutorial is the second part to the android image viewer tutorial series.
Where the viewers will be shown how to create a basic android application that loads an image thumbnail and then displays it on the full screen.
This android tutorial series targeted towards beginners to android who would like to learn how to create a basic android application.
In this tutorial we will introduce android intents and show how they can be used to pass requests to other parts of the android os.
Get Code
The code from this tutorial can be found on github here
https://github.com/mobapptuts/android_image_viewer.git Tag image-viewer-intent
or you can run this command
git clone https://github.com/mobapptuts/android_image_viewer.git –branch image-viewer-intent
Code Samples
Add a result code member for the intent request
private static final int REQUEST_OPEN_RESULT_CODE = 0;
Create the intent and send it
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_view_main); mImageView = (ImageView) findViewById(R.id.imageView); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, REQUEST_OPEN_RESULT_CODE); }
Android Image Viewer Action Open Document Summary
In this tutorial we learned
- How to create an android intent
- Adding a category to the intent request
- Specifying the types of files for the intent request
- Sending the intent