I'm using different tab, almost the sames.
In my app, I want to take picture with the camera with this code
public void takePicture(View v) {
imageFilePath = file_path + "/" + "Photo_" + idFiche + ".png";
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(takePictureIntent, REQUEST_CODE_PICTURE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
InputStream stream = null;
if (requestCode == REQUEST_CODE_PICTURE && resultCode == Activity.RESULT_OK) {
//blablabla
}
}
It works well for some tab, but with others, it's impossible to click on the activation button of the photo app to save the picture, as indicated in below picture with the red border.
I think the camera app is wrong, even if I can take picture from the device directly (not from my app), but how to solve it? Can I delete the picture app and use another app with the same code? Or launch a specific app through new intent???
Thank for your help
I think the camera app is wrong
Most likely. Many camera apps seem to go through little testing of ACTION_IMAGE_CAPTURE.
how to solve it?
Stop using ACTION_IMAGE_CAPTURE. Use the camera APIs directly or through a third-party library.
Can I delete the picture app
If by "the picture app", you mean "the camera app", it is likely that the camera app is pre-installed and cannot be uninstalled. Plus, the user may not appreciate you attempting to uninstall their camera app.
and use another app with the same code?
Your code will already give the user a choice of camera apps, if there is more than one that supports ACTION_IMAGE_CAPTURE installed on the device.
Or launch a specific app through new intent?
It is highly unlikely that your desired "specific app" exists on the device.
Related
in my app i would like to have the user choose an image from the gallery and retrieve the result (thumbnail + full image uri). i would also like the user to be able to choose which gallery app to open (i.e. default gallery app or some other gallery app).
initially, according to this guide by google i copied and pasted this code:
public void selectImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) {
Bitmap thumbnail = data.getParcelable("data");
Uri fullPhotoUri = data.getData();
// Do work with photo saved at fullPhotoUri
...
}
}
while it does get me the thumbnail and the full Uri in onActivityResult(...), the problem is that it does not open a chooser for the user to select which gallery app to use and instead it opens this thing (see images below), which i assume is a default "image-chooser" thing where you could select another app via a menu.
i feel it's silly that the user would have to open this default "image chooser" first and once they are already in an "image chooser", select the gallery app that they actually want to use (sure, the user could just choose the image from this thing, but i want to give them a convenient choice).
so i changed my code to this and it does indeed display a proper chooser for the user and he can go straight to hes favorite gallery app:
Intent intent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
if (intent.resolveActivity(getActivity().getPackageManager()) != null)
{
startActivityForResult(intent, Utils.REQUEST_CODE_OPEN_GALLERY);
}
however now i have a new problem: in onActivityResult(...) the line data.getParcelable("data"); returns null. in other words, i don't get back a thumbnail.
i also tried
Bundle extras = data.getExtras();
Bitmap thumbnail = (Bitmap) extras.get("data");
but "extras" is null.
is it possible to have a proper "app chooser" AND get back a thumbnail?
however now i have a new problem: in onActivityResult(...) the line data.getParcelable("data"); returns null. in other words, i don't get back a thumbnail.
You do not get that from ACTION_GET_CONTENT, either. You can tell this by reading the documentation for ACTION_GET_CONTENT. It is certainly possible that there are some buggy ACTION_GET_CONTENT activities that happen to return a thumbnail Bitmap in a "data" extra, but you should not assume that any user will have such a buggy ACTION_GET_CONTENT activity, let alone choose it. Besides, ACTION_GET_CONTENT is not limited to images; what would a "thumbnail" be of application/json or text/csv be?
Likewise, if you read the documentation for ACTION_PICK, you will see that there is no discussion of a thumbnail.
is it possible to have a proper "app chooser" AND get back a thumbnail?
No, insofar as you do not get a thumbnail back from anything except ACTION_IMAGE_CAPTURE, and that is for taking photos.
Followed Android documentation to write code for launching native camera via intent:
http://developer.android.com/training/camera/photobasics.html
Problem: I am using Andorid Native Camera App for taking pictures from my app and launching via intent as mentioned in above link (MediaStore.ACTION_IMAGE_CAPTURE) and camera is launched successfully. When I click camera button of Native app to take pictures, image preview is mirrored while taking selfie (left image appears right) which selfie user would hate as image preview is not what he clicked.
Second - once image is clicked, it shows image preview and waits for user input for acceptance or rejection of picture.
Once image is accepted, OnStartActivityResult (as mentioned in above link) function receives the call and saves image to gallery. Strange thing here is that: Image gets inverted by 180 degree and then saved which is very weird behaviour.
Finally, two problems here: Image Preview Mirroing issue before user approves and while saving image invert issue (180 degree reverse).
Device: Samsung A6 Edge
Android: 5.1
Camera In Manifest File: Android.hardware.camera2 as Camera is deprecated
Please advise how can i fix above two issues.
Also- I have another doubt: Shall i use android native camera app or write the code using Camera Framework and launch custom camera? My requirement just to click pictures and show preview and save it with correct orientation. After searching a lot, I am doubtful - Can native camera app fix these issues? but your expert advise can help on this.
Any quick support and guidance on this is highly appreciated. Thanks in advance !
Here is the code:
public void triggerCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagePath = AppPhotoHelper.getOutputMediaFile();
// Continue only if the File was successfully created
if (imagePath != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(imagePath));
takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.setImagePath(imagePath);
this.startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
}
}
onActivityResult function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK ) {
//AppPhotoHelper is my class to show image in gallery
AppPhotoHelper.displayInGallery(this.getImagePath(), this);
//Image captured and stored in gallery ... camera invoked for next shot after doing some business processing
this.triggerCamera();
}
else if (resultCode == RESULT_CANCELED) {
return;
}
else {
return;
}
}
}
As mentioned in my post, the native camera app differs from device to device. Did you try your code with another device or emulator? I published a library on github that solves many issues, including the image orientation across a wide variety of devices. Feel free to check it out, run the sample code on your device and check if it works properly for your use case.
I have written a simple application in which the user can:
press a button to open the camera application
take pictures with the camera application
Is there any way to disable the shutter sound of the camera from my code?
I currently hold an Orange Nivo phone with Android 4.1.2 version on it.
A secion of my code is:
public void onClick(View v) {
try {
f = createImageFile();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath());
Bitmap newphoto = Bitmap.createScaledBitmap(photo, 200, 200, false);
imageView.setImageBitmap(newphoto);
I would appreciate any suggestions on how to achieve this effect.
I know that there are applications on Android store that take pictures without the shutter sound, so i suppose there must be a way to do this without rooting the phone.
The simple answer is: you can not!
The reason is that it is against the law to take a picture without the shutter making sound, this is for privacy concerns. Moreover, as you will notice, you can't take a picture even when your camera preview is not set properly, still for privacy reasons.
At this point you have four options:
Find a way to hack the API
Root the phone and disable the shutter sound
Write your own native code for the camera...but this may be highly dependant on the device you're using it
Use the siplest way that is also the way used by most (if not all) the silent camera
applications in the market. Simply intercept the preview frame via the onPreviewFrame callback from your onClickListener and then save it as an image. The major drawback here is that the maximum preview resolution is far less than the maximum picture resolution so the photo you will take this way will have a fairly low resolution. Indeed if you read the comments on the silent camera apps on the market you will see a lot of people complaining about the resolution of the images not being so high. This is the reason why: they use the trick I exaplained you above.
To conclude, there is no easy way to achieve what you want!
I am developing on a Android 4.0.3 device. How do I open a file browser for my app? Is there one built in the to Android SDK? Do I have to write my own?
I don't want my app to depend on a the user installing a separate app for file browsing.
To get a file from a file browser, use this:
Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
fileintent.setType("gagt/sdf");
try {
startActivityForResult(fileintent, PICKFILE_RESULT_CODE);
} catch (ActivityNotFoundException e) {
Log.e("tag", "No activity can handle picking a file. Showing alternatives.");
}
I'm not quite sure what the gagt/sdf is for... it seems to work in my app for any file.
Then add this method:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Fix no activity available
if (data == null)
return;
switch (requestCode) {
case PICKFILE_RESULT_CODE:
if (resultCode == RESULT_OK) {
String FilePath = data.getData().getPath();
//FilePath is your file as a string
}
}
If the user doesn't have a file manager app installed or preinstalled by their OEM you're going to have to implement your own. You might as well give them a choice.
I hope this one will help you for file picking:
public void performFileSearch() {
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
// To search for all documents available via installed storage providers,
// it would be "*/*".
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
The code is from this documentation:
https://developer.android.com/guide/topics/providers/document-provider.html
Refer to it for more information.
If someone would still need it for newer versions, it got updated with developing Storage Access Framework by Google for SDK >= 4.4. Check this Google site for further details:
https://developer.android.com/guide/topics/providers/document-provider.html
There is no single file-management app that is installed across all devices.
You probably want your app to be also working on devices with Android 3.x or lower.
The best choice you have though is writing your own file-manager. It isn't as much effort as it might sound, there is a lot of code on this already out there on the web.
I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..