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
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { // note that data will be null | |
if (resultCode == Activity.RESULT_OK) { | |
if (requestCode == REQUEST_CODE_CAMERA) { | |
// imageFile will have the photo in it so do whatever you want with it | |
} | |
} | |
} |
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
<application> | |
... | |
<provider | |
android:name="android.support.v4.content.FileProvider" | |
android:authorities="{your.app.package}.fileprovider" | |
android:exported="false" | |
android:grantUriPermissions="true"> | |
<meta-data | |
android:name="android.support.FILE_PROVIDER_PATHS" | |
android:resource="@xml/file_paths"/> |
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
public void startCameraIntent() { | |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
// Ensure that there's a camera activity to handle the intent | |
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
try { | |
imageFile = createImageFile(); | |
} catch (IOException e) { | |
// file wasn't created | |
} |
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
int rotateAngle; | |
void rotatePhoto(){ | |
rotateAngle += 90f; | |
if (rotateAngle == 360f) { | |
rotateAngle = 0; | |
} | |
photoImageView.setRotation(rotateAngle); // just rotate the image view for the user | |
} |
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
<manifest ...> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" | |
android:maxSdkVersion="22" /> | |
<!-- that should be android:maxSdkVersion="18" ended up having this issue: | |
http://stackoverflow.com/questions/31831453/getexternalfilesdir-fail --> | |
<!--- If you want to save to the public image directory (the image gallery), you need to do this: | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
---> | |
... |
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
File imageFile; // use this to keep a reference to the file you create so that we can access it from onActivityResult() | |
private void createImageFile() throws IOException { | |
String imageFileName = "image" + System.currentTimeMillis() + "_"; // give it a unique filename | |
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); | |
// use this if you want android to automatically save it into the device's image gallery: | |
// File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) | |
imageFile = File.createTempFile(imageFileName, ".jpg", storageDir); | |
} |