In my App, there is provision of taking picture through Camera and send it for Crop but when the Camera App opens with the sent image and the user crops and clicks on OK, a toast is displayed by the Camera App,
"Unable to save cropped images"
Here is the code I have written for it:
public static void sendImageForCrop(final Activity activity, final Uri mImageCaptureUri){
final ArrayList<CropOption> cropOptions = new ArrayList<>();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
List<ResolveInfo> list = activity.getPackageManager().queryIntentActivities(
intent, 0);
int size = list.size();
if (size == 0) {
Toast.makeText(activity, "Can not find image crop app",
Toast.LENGTH_SHORT).show();
} else {
//intent.setData(mImageCaptureUri);
intent.setDataAndType(mImageCaptureUri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputX", 150);
intent.putExtra("outputY", 150);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
try{
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(File.createTempFile("temp", null, activity.getCacheDir())));
}catch(IOException ioe){
// It is unfortunate that the Photo can't be cropped.
// Show a Toast for this.
Toast.makeText(activity, "The photo couldn't be saved :(. Try clearing the App data.", Toast.LENGTH_SHORT).show();
return;
}
activity.startActivityForResult(i, CROP_FROM_CAMERA);
}
}
And here is the toString() of the Intent object:
Intent { act=com.android.camera.action.CROP dat=file:///storage/emulated/0/Snap_1508218098533.jpg typ=image/* flg=0x2 (has extras) }
What might be the problem here?
EDIT: As requested, here is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.example"
android:versionCode="156"
android:versionName="1.2.54">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>
<uses-sdk tools:overrideLibrary="com.braintreepayments.api.core,com.android.volley,com.paypal.android.sdk.onetouch.core,com.braintreepayments.api" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:name="android.hardware.microphone"
android:required="false" />
<!-- Tell the system this app requires OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00015000"
android:required="true" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:name="com.example.example.UILApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/applicationlogo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/Theme.MyTheme">
<!-- List of Activities here -->
<provider
android:name=".provider.GenericFileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
</application>
</manifest>
I think the problem is may be with the path where your trying to save,
try to use like below
public void choosePhoto(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", int_Width_crop);
intent.putExtra("outputY", int_Height_crop);
intent.putExtra("scale", false);
intent.putExtra("return-data", true);
File photo = new File(Environment.getExternalStorageDirectory(), "cropped_image.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(intent, CHOOSE_PICTURE);
}
I had same problem but I fixed by changing the path of saved image directory as below -:
File croppedImageDirectory = new File(Environment.getExternalStorageDirectory()+"/croppedImage");
Or, see this answer may help you-: stackoverflow.com/a/1976115
May help you
I know this would be a considered a hack approach by many of you but it works!
intent.putExtra(MediaStore.EXTRA_OUTPUT, (String)null);
Reasoning
Well, I looked up the source of Gallery App in MarshMallow(one of the places the crop was failing; other was the Photos App) and found this method that handles a CROP request:
private void saveOutput(Bitmap croppedImage) {
if (mSaveUri != null) {
OutputStream outputStream = null;
try {
outputStream = mContentResolver.openOutputStream(mSaveUri);
if (outputStream != null) {
croppedImage.compress(mOutputFormat, 75, outputStream);
}
} catch (IOException ex) {
// TODO: report error to caller
Log.e(TAG, "Cannot open file: " + mSaveUri, ex);
} finally {
Util.closeSilently(outputStream);
}
Bundle extras = new Bundle();
setResult(RESULT_OK, new Intent(mSaveUri.toString())
.putExtras(extras));
} else if (mSetWallpaper) {
try {
WallpaperManager.getInstance(this).setBitmap(croppedImage);
setResult(RESULT_OK);
} catch (IOException e) {
Log.e(TAG, "Failed to set wallpaper.", e);
setResult(RESULT_CANCELED);
}
} else {
Bundle extras = new Bundle();
extras.putString("rect", mCrop.getCropRect().toString());
File oldPath = new File(mImage.getDataPath());
File directory = new File(oldPath.getParent());
int x = 0;
String fileName = oldPath.getName();
fileName = fileName.substring(0, fileName.lastIndexOf("."));
// Try file-1.jpg, file-2.jpg, ... until we find a filename which
// does not exist yet.
while (true) {
x += 1;
String candidate = directory.toString()
+ "/" + fileName + "-" + x + ".jpg";
boolean exists = (new File(candidate)).exists();
if (!exists) {
break;
}
}
try {
int[] degree = new int[1];
Uri newUri = ImageManager.addImage(
mContentResolver,
mImage.getTitle(),
mImage.getDateTaken(),
null, // TODO this null is going to cause us to lose
// the location (gps).
directory.toString(), fileName + "-" + x + ".jpg",
croppedImage, null,
degree);
setResult(RESULT_OK, new Intent()
.setAction(newUri.toString())
.putExtras(extras));
} catch (Exception ex) {
// basically ignore this or put up
// some ui saying we failed
Log.e(TAG, "store image fail, continue anyway", ex);
}
}
final Bitmap b = croppedImage;
mHandler.post(new Runnable() {
public void run() {
mImageView.clear();
b.recycle();
}
});
finish();
}
You see the statement, if (mSaveUri != null) {. It handles the case where we provide a null Uri. The assumption is that the 3rd party App is likely to handle the case where we provide a null Uri.
Now, I tested it with a couple of Apps and it worked. But by no means, this solution is an ideal one.
Related
Team,
Trying to Work on Camera Taking Picture but everytime getting result as Android.App.Result.Canceled and data as null on OnActivityresult function.
TakePicture.Click += delegate
{
if (slabDetails != null)
{
File SlabFile = new File(Constants.INVENTORY_PATH, slabDetails.ExtSlabNo + ".jpg");
//if (SlabFile.Exists()) { SlabFile.Delete(); }
//SlabFile.CreateNewFile();
imageUri = Uri.FromFile(SlabFile);
//var documentsDirectry = ApplicationContext.GetExternalFilesDir(Environment.DirectoryPictures);
//File cameraFile = new Java.IO.File(documentsDirectry, "default_image" + ".jpg");
//Uri photoURI = Uri.FromFile(cameraFile);
Intent camIntent = new Intent(MediaStore.ActionImageCapture);
camIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
camIntent.PutExtra(MediaStore.ExtraOutput, imageUri);
camIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
camIntent.AddFlags(ActivityFlags.GrantWriteUriPermission);
StartActivityForResult(camIntent, 2);
}
};
On Activity Result Function
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case 2:// From Camera
if (resultCode == Result.Ok)
{
try
{
new SyncDataTask(this, data, 1, db).Execute();
}
catch (Exception ex)
{
var method = System.Reflection.MethodBase.GetCurrentMethod();
var methodName = method.Name;
var className = method.ReflectedType.Name;
MainActivity.SaveLogReport(className, methodName, ex);
}
catch (OutOfMemoryError ex)
{
ex.PrintStackTrace();
}
}
}
}
Using Xamarin Native Android deploying in Android API 33 and Android 12 Version tablets. It Return the Image and Works good on android version 11 tablets.
Provided permissions in android manifest file as per Android 13 Tutorials
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.MANAGE_MEDIA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
So, I would like to return Android.App.Result.Ok and data in ActivityResult. So, Do anybody faced the issue. Please help me in this Case. Thanks in Advance.
I found an anomaly during tests with this particular device, the details are below:
Hardware: samsung,SM-A326B (Smartphone Samsung A32)
OS: Android 12
ONE UI: 4.1
Google Play: 01/may/22
Patch level: 01/june/22
These are the specs of one device that works properly, the only differences that I see are related to different version of the patch level.
Hardware: samsung,SM-A515F (Smartphone Samsung A51)
OS: Android 12
ONE UI: 4.1
Google Play: 01/may/22
Patch level: 01/may/22
I have implemented a customization of camera2 in my application, this always works except with this device, the specific anomaly is that the images are saved completely white and are corrupted, the image can only be recovered by third party software.
These are the permissions I ask for in the manifest:
<uses-feature android:name="android.hardware.location.gps " />
<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
This is the code that I use to save the images
public void saveCameraImage(Image mImage, File mFile, String mOrientation, Context context) {
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(mFile);
fileOutputStream.write(bytes);
} catch (IOException e) {
wil.WriteFile("saveImage - Exception: " + e.getMessage(), context);
} finally {
mImage.close();
if (null != fileOutputStream) {
try {
fileOutputStream.close();
} catch (IOException e) {
wil.WriteFile("saveImage - Exception: " + e.getMessage(), context);
} finally {
saveExifData(mFile.getPath(), context);
createThumbs(mOrientation, mFile, context);
}
}
}
}
This is the function that I named "saveExifData"
private void saveExifData(String filepath, Context context) {
try {
if (filepath.endsWith(IMAGE_FORMAT)) {
File file = new File(filepath);
if (file.exists()) {
DbGest dbGest = DbGest.getInstance(context);
String dateTime = dbGest.getTimestampFromFileToSend(filepath, "dateTime", context);
String dateTimeGps = dbGest.getTimestampFromFileToSend(filepath, "gps", context);
String dateTimeDesc = dbGest.getTimestampFromFileToSend(filepath, "dateTimeDesc", context);
ExifInterface exifInterface = new ExifInterface(filepath);
exifInterface.setAttribute(ExifInterface.TAG_COPYRIGHT, "xxxxx ");
exifInterface.setAttribute(ExifInterface.TAG_MODEL, Build.MANUFACTURER + "," + Build.MODEL);
exifInterface.setAttribute(ExifInterface.TAG_SOFTWARE, dbGest.getSetting("appName", context));
exifInterface.setAttribute(ExifInterface.TAG_DATETIME, dateTime);
exifInterface.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, dateTime);
exifInterface.setAttribute(ExifInterface.TAG_USER_COMMENT, "Immagine scattata tramite " + dbGest.getSetting("appName", context) + " il " + dateTimeDesc);
CoordinatesData position = DbGest.getInstance(context).getBetterPositionKnown(context);
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, String.valueOf(position.getLat()));
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, String.valueOf(position.getLng()));
exifInterface.setAttribute(ExifInterface.TAG_GPS_DATESTAMP, dateTimeGps);
exifInterface.setAttribute(ExifInterface.TAG_GPS_SPEED, String.valueOf(position.getSpeed()));
exifInterface.setLatLong(position.getLat(), position.getLng());
exifInterface.saveAttributes();
}
}
} catch (Exception e) {
wil.WriteFile("saveExifData - Exception: " + e.getMessage(), context);
}
}
So I guess it's not a permission issue, also there are no exceptions, so I don't know how to fix this
After several test and debugging I find the cause of the bug.
The problem it is in the "saveExifData", for some reason this row of code
exifInterface.setAttribute(ExifInterface.TAG_COPYRIGHT, "xxxx");
it is the cause of the problem
When the activity opens, a dialog window opens asking the user to either take a picture from the camera, or choose one from the gallery. As soon as I hit the button to open the camera, the app crashes and I get a Null Pointer exception related to getting the URI. I have been following Google's walkthrough for saving pictures form the camera and can't seem to find where the issue is.
Line where the error occurs:
Uri photoURI = FileProvider.getUriForFile(CreatePostActivity.this,
"xyz.beerme.beerme.provider",
photoFile);
Whole method:
cameraButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(intent.resolveActivity(getPackageManager()) != null){
File photoFile = null;
try{
photoFile = createImageFile();
} catch (IOException ex){
Snackbar message = Snackbar.make(findViewById(R.id.activity_create_post), "Error creating image", Snackbar.LENGTH_LONG);
message.show();
}
if(photoFile != null){
Uri photoURI = FileProvider.getUriForFile(CreatePostActivity.this,
"xyz.beerme.beerme.provider",
photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(intent, REQUEST_CAMERA);
}
}
dialog.dismiss();
}
});
createImageFile method:
private File createImageFile() throws IOException{
String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_beerme";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="xyz.beerme.beerme">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:supportsRtl">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="redacted" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="xyz.beerme.beerme.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" ></meta-data>
</provider>
<activity android:name=".PostsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.categroy.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".CreatePostActivity"></activity>
</application>
</manifest>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/xyz.beerme.beerme/files/Pictures" />
</paths>
Try Below code for createImageFile method
private File createImageFile() {
File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
// path = path + (timeStamp + "1jpg");
try {
file = File.createTempFile(timeStamp, ".jpg", storageDir);
} catch (IOException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= 24)
mCurrentPhotoPath = String.valueOf(FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider", file));
else
mCurrentPhotoPath = String.valueOf(Uri.fromFile(file));
return file;
}
In case anyone finds this in the future, I typed "provider" instead of "fileprovider". As provider does not exist, that is the source of the exception.
I have problem with finding photo after saving.
Here is how i am creating Intent to take photo from camera and save filePath to it.
private void takePhoto(int position)
{
Meter meter = adapter.getItem(position);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File tempFile = createTempFile(meter.id, JPEG_FILE_SUFFIX, storageDir);
if(tempFile != null)
{
lastPhotoPath = tempFile.getAbsolutePath();
Log.d(TAG, "temp picture path=" + lastPhotoPath);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(tempFile));
try
{
startActivityForResult(takePictureIntent, TAKE_PHOTO_REQUEST);
lastPhotoPosition = position;
}
catch(ActivityNotFoundException exc)
{
Log.e(TAG, "activity to take photo not found");
}
}
}
Then later i want to upload this image to server.
Here is how i am doing this.
public void compose(OutputStream out) throws DataStorageException
{
Log.d("MainMenuActivity", "file not found in path " + path);
InputStream in = null;
try
{
in = new BufferedInputStream(new FileInputStream(path));
// TODO: there is a better way
byte[] buf = new byte[8192];
while(true)
{
int length = in.read(buf);
if(length < 0)
break;
out.write(buf, 0, length);
}
}
catch(FileNotFoundException exc)
{
throw new DataStorageInternalErrorException("FileNotFoundException, FileRequestComposer compose");
}
catch(IOException exc)
{
// TODO: probably network error
throw new DataStorageInternalErrorException("IOException, FileRequestComposer compose");
}
finally
{
if(in != null)
{
try
{
in.close();
}
catch(IOException exc)
{
// FIXME
}
}
}
}
I check filePath from saving and filePath to save they both completely identical:
temp picture path=/mnt/sdcard/Pictures/19520983731349.jpg
file not found in path /mnt/sdcard/Pictures/19520983731349.jpg
And the exception is thrown in method compose()
FileNotFoundException, FileRequestComposer compose
Any ideas where i am doing wrong?
P.S. And i can't see this file in /mnt/sdcard/Pictures mb. he is lost or somethinf like this? Please suggest any ideas.
P.P.S Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vodomer"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="19"/>
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:label="#string/app_name"
android:name="com.vodomer.DatabaseApplication" >
<activity android:name="Vodomer"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.AddressesListActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
>
</activity>
<activity android:name=".activity.MainMenuActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
>
</activity>
<activity android:name=".activity.MetersActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"
>
</activity>
<activity android:name=".activity.PersonalAccountActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
>
</activity>
</application>
</manifest>
The problem is likely with the way you create File. Instead of createTempFile try regular constructor :
File tempFile = new File(storageDir, meter.id + JPEG_FILE_SUFFIX);
Generally, you also want to make sure that your storageDir folder exists and create it with mkdirs if needed.
Add this path for storing image on sdcard.
final String uploadFilePath = "/mnt/sdcard/";
i have a problem with code of take a picture and save. It crash when i launchCamera().
Can you help me please?
private void launchCamera() {
try {
mOutputFile = File.createTempFile("prova", null);
Intent intentCamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intentCamera.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(mOutputFile));
startActivityForResult(intentCamera, CAMERA_REQUEST);
} catch (Exception e) {
Toast t = Toast.makeText(this, "ERROR:\n" + e.toString(), Toast.LENGTH_LONG);
t.show();
}
}
I am using this piece of code try it out :
/**
* This method is used to start the camera activity and save the image taken as the imagename passed
*
* #param imagename : this is the name of the image which will be saved
*/
private void clickPicture(String imagename) {
Intent getCameraImage = new Intent("android.media.action.IMAGE_CAPTURE");
File cameraFolder;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"myfolder/");
else
cameraFolder= context.getCacheDir();
if(!cameraFolder.exists())
cameraFolder.mkdirs();
String imageFileName = imagename;
File photo = new File(Environment.getExternalStorageDirectory(), "myfolder/" + imageFileName);
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
Uri.fromFile(photo);
startActivityForResult(getCameraImage, 1);
}
and add the permisson in your manifest file :
<uses-permission android:name="android.permission.CAMERA" ></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Maybe you didn't added the necessary permissions in the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Also I would suggest you to go over this blog post I wrote on this topic of taking a picture using the build-in Camera Activity:
Take Picture with build in Camera Activity
To access the device camera, you must declare the CAMERA permission in your Android Manifest