Chapter 9. Ready-to-use snippets
Do you sometimes use the same code in different applications? If so, this chapter is for you. We’ll go through some code snippets that you can copy and paste into any Android application.
One of the nicest features about Android is the intent system. If you want to share something with another application, you can use an intent to do so. If you want to open a link, you have an intent for that. In Android, almost everything can be done with an intent.
If you use the mobile messenger app, WhatsApp, you might know that you can share images with your contacts from an image in the gallery or by taking a photo. The dialog presented to the user to pick an image from the gallery or to take a picture is shown in figure 35.1. Obviously, this was created with intents but, unfortunately, it can’t be done with only one.
In this hack, we’ll analyze how this can be done. We’ll see which is the intent to take a photo, which is the intent to pick a picture from the gallery, and how to combine both.
The intent to take a photo using the camera app is the following: