This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Using the Intent data that the Gallery app returns, this method will | |
* retrive the filepath location of the image that the user have | |
* selected. | |
* | |
* Known issues: This does not work for getting images from Google Drive and | |
* Pisca. | |
*/ | |
public String getGalleryImagePath(Intent data) { | |
Uri imgUri = data.getData(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start intent to get image using using any image viewing app available on the device. | |
Intent intent = new Intent(); | |
intent.setType("image/*"); | |
intent.setAction(Intent.ACTION_GET_CONTENT); | |
startActivityForResult(intent, GALLERY_CHOOSER_INTENT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start intent to get image using device's default gallery app. | |
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
startActivityForResult(intent, GALLERY_INTENT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (resultCode == RESULT_OK) { | |
... | |
else if (requestCode == CAMERA_WITH_FILEPATH) { | |
// Get the image from the filepath you specified when you | |
// started the camera intent. | |
String filepath = getOutputLink(TEMP_JPEG_FILENAME); | |
Bitmap img = BitmapFactory.decodeFile(filepath); | |
mImage.setImageBitmap(img); | |
Toast.makeText(this, "Image is saved in: " + filepath, Toast.LENGTH_SHORT).show(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new File object with specified filepath, where the | |
// captured image will be located. | |
File file = new File(getOutputLink(TEMP_JPEG_FILENAME)); | |
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); | |
startActivityForResult(cameraIntent, CAMERA_WITH_FILEPATH); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Creates a new file path into the standard Android pictures directory. | |
*/ | |
private String getOutputLink(String filename) { | |
String directory = ""; | |
// Check if storage is mounted. | |
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { | |
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), | |
getResources().getString(R.string.app_name)); |
NewerOlder