So, I am developing a small game for my final school project, and I am having this problem, whenever I take a picture with the front facing camera, it saves it upside down, when I use the good old back camera however, it's all fine and it takes the photo properly. Here's the code that I'm using to take the picture:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "goQuiz/profilePic.jpg"
);
Uri tempuri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
I used this video to help me get the code done: Video.
Any help will be greatly apreciated, thanks.
Related
This question already has answers here:
Android ACTION_SEND event: "messaging failed to upload attachment"
(2 answers)
Closed 5 years ago.
I am trying to create a Sharing Intent for an Android App to share images to other apps. However, I'm getting this really weird result when implementing this feature.
I have a share button that when I click on the button, it runs the following method:
private void shareIntent() {
Uri currUri = Uri.parse(data.get(pos).getUrl());
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, currUri);
sharingIntent.setType("image/jpg");
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.share_to)));
}
data.get(pos).getUrl() returns the URL of a custom class I made that implements Parcelable, and when printing it out, it returns a directory like the following: "/storage/emulated/0/Pictures/primitive/Primitive-79538313.jpg"
The intent works at first, opening the sharing menu. However, when I click on most applications, it either crashes the application or it gives an error... except with Google Photos, which uploads the photo properly to the gallery.
Firstly, I'm wondering what I'm doing wrong to cause this issue in the other apps. Also, I'd like to know if someone has an explanation as to why only Google Photos allows the sharing feature to work, while many of the other apps I've tested do not.
For reference, here are some examples I've run with the sharing intent. When I try to share the image, it crashes Hangouts. It gives a "failed to load image" error message in Snapchat, "Unable to share file" in Slack and Gmail, "Upload was unsuccessful" in Drive, "Messenger was unable to process the file" in, well, Messenger, and "Couldn't load image" in GroupMe. It doesn't load the image in Facebook but doesn't crash nor give an error.
Thank you for any help or feedback you can provide!
EDIT:
This seemed to work without trying to get around App Permissions:
private void shareIntent() {
File imageFile = new File(data.get(pos).getUrl());
Uri uriToImage = FileProvider.getUriForFile(
this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(DetailActivity.this)
.setStream(uriToImage)
.getIntent();
shareIntent.setData(uriToImage);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Thank you to everyone that responded!
Change your code to this
private void shareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jepg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+data.get(pos).getUrl()));
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
Add this code in your activity onCreate()
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
First of, this is not a duplicate, I've seen similar posts but with no good answers. Now, this is the menu I'm talking about:
This only happens in some devices, in my particular Samsung Galaxy S3 Neo, it does well, and everything that it's supposed to, but on a friend of mines Wiko (French brand, but pretty good), aswell as on the emulator above, it just does nothing when I click on "save". Here is my code if you could take a look:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), path);
Uri tempuri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
If you need any more details tell me :)
I am saving a bitmap . It saves to some root. But doesn't show in gallery. it show in gallery after restarting the device. I tried to send broadcast but it doesn't work for android 4.4.How can I do it to work for api 9-19
The built-in Gallery scans the phones memory when it thinks it's necessary. You can't force it to. Normaly restarting the gallery should help.
Edit:
I might have found an intent to refresh the gallery:
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
getApplicationContext().sendBroadcast(mediaScanIntent);
(f is the file wich has been added and should be scanned.) I haven't tried this yet, but it seems legit.
I would like to allow the user to take a photo, and when finished, have it passed directly into a variable (Bitmap preferably) instead of saved to memory. I've tried using the default android camera intent but cannot seem to stop it from saving to memory and showing up in the gallery.
Any suggestions?
What I have so far is this:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, 1);
}
But this saves the picture in the gallery. I would like to get the image without saving it in the gallery.
Here's a nice example given at official android developer site: http://developer.android.com/training/camera/photobasics.html
Hope this would be helpful.
What i want to do is to capture image from Camera and then want to crop With equal Width, height. I am using following code which is working fine in Samsung S3 and similar devices. But when i tested application in samsung galaxy S4 it is not working just Capturing image and saved into sdcard but no cropping tool is Appeared in between.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
// ******** code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", com.app.controller.Constants.MAX_WIDTH);
intent.putExtra("outputY", com.app.controller.Constants.MAX_HEIGHT);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
// Do nothing for now
}
Please help me if anybody have any experience in this reference.
Android does not have a crop intent/tool. That's why it can work in some phones, but not in others.
You can read more about this in this website from CommonsWare
http://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html
You can checkout some libraries that do that (both retrieved from the website above):
https://github.com/lvillani/android-cropimage
https://github.com/biokys/cropimage
https://github.com/MMP-forTour/cropimage
https://github.com/dtitov/pickncrop