I've an application that opens activity camera with the following code:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + image)));
activity.startActivityForResult(intent, CAMERA_ACTIVITY_OK);
The problem is that the camera application, after some "snapshots", returns the following error:
Activity Camera (in application Camera) is not responding.
After that, the camera application doesn't works anymore.
This problem happens only with Android 2.3 version
Could you help me please?
Thanks
Snapshot"s"? As in more than one? That intent should only produce one shot, or the user can cancel the shot (producing no image). Are you calling the intent multiple times? If so, make sure the target image file (EXTRA_OUTPUT) is different each time. I probably can't help you without seeing more of your code or the error log.
BTW: Using the Camera app with Intents is now covered in the Android Developer documentation:
http://developer.android.com/guide/topics/media/camera.html#intents
Related
In my app I run camera intent to take picture with photo App, with this code below:
Activity activity;
File currentPhotoFile;
Intent capturePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri = GenericFileProvider.getUriForFile(activity, activity.getPackageName() + providerSufixName, currentPhotoFile);
capturePhoto.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(capturePhoto, REQUEST_PHOTO);
And after that I catch the created photo in my activity.onActivityResult function in Activity
If I have only one! photo App on my mobile device - everything works fine.
But! If I installed on my device one more! photo application - the code above is not working :(
In case two photo apps, when I call activity.startActivityForResult - I see andoid system dialog with list of all available photo apps. (like Intent.createChooser calling). I select from it, preferable photo app and tap "JUST ONCE". Selected application runs, I take picture inside it and press Ok button for returning back to my App.
At this moment I recieve callback to my onActivityResult with my code: REQUEST_PHOTO but with requestCode = RESULT_CANCELED. And that's all :(
Why it's not working?
And how I can resolve this issue and use camera intent with more than one photo application?
The problem was that in manifest I have option:
android:launchMode="singleInstance" for my activity.
<activity
android:name="MyActivity"
android:launchMode="singleInstance"
>
For solving above issue you should remove singleInstance option from manifest file (or replace it within singleTask option).
This is resolve the issue and onActivityResult is properly working.
I have a problem, when I startActivityForResult to take picure, resultCode is always Activity.RESULT_CANCELED (0) if there is two or more camera apps that can handle that intent (app chooser appears). But if I set one of them as default app and next time it doesn't offer me a chooser, everything works fine, and it takes picture and detects it in a onActivityResult in my fragment that started startActivityForResult().
Same thing happens when I try to open gallery to select picture. If there are two gallery apps, I choose either one of them, picture selection result is always 0.
This is the code I use to start camera app:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, AppConstants.TAKE_PICURE_CAMERA_REQUEST_CODE);
}
I had the same issue, when my activity has launchMode="singleTask", but I change to singleTop and that solve the problem
I just updated my Poco X3 to Android 11 and now I have the same problem... It's probably a bug in MIUI (12.0.8). It works fine on other Android 11 devices.
Changing launchMode does not work. However when I detect a MIUI user I circumvent the chooser and just open the first camera app it finds.
Worst thing is that you can't really detect when this issue occurs. So you can't log when it goes wrong and therefore you can't find out which users are experiencing this issue.
The same issue also occurs when you try to get a photo from a gallery, or when you try to open a photo in a photo app. The latter results in a 'cannot find photo' message.
I got a problem similar to (How to take multiple photos before dismissing camera intent?)!
how ever he used the:
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
I need to use somewhat like this:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
for(int i=0;i<2;i++){
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
since i need to take exactly 2 photos, preview it with the default check or x of using MediaStore.ACTION_IMAGE_CAPTURE(to remove the hassle of displaying it to an imageview, go back again to capture)
then only go back to the main activity, knowing the data that i had taken 2 photos/saved it.
however, when i used that for loop, it returned only the last image taken, and it resized 2 times( i have a code that resizes 25% of the original captured photo, so after the code executed, it resized to 6.25% of original(1/4 of 25%) before it returns to the main activity).
Can someone give me light what is happening and give me a solution? Thanks a lot in advance! :D
As much as possible, i want to use the built in camera app, since it has a lot of other functions readily available compared to having the hassle of building your own custom camera. Btw im using android jellybean. 4.1.1
Call your second startActivityForResult() from the onActivityResult() you get from your first startActivityForResult(). Bear in mind that startActivityForResult() is asynchronous -- the other activity is not started right away.
I am working on app which uses WebView to display its content. However, it needs to open camera or gallery in order to choose picture:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 1);
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, 2);
It's working fine on most devices, but on HTC One and few others both intents destroys my activity, so webview is being reloaded while going back. I don't have noHistory flag in AndroidManifest.xml. What might be causing that issue? Can I avoid destroying my activity here?
It is normally, that Android kills your Activity when other app runs.
You must save Activity state in onSaveInstanceState and when activity will be recreated restore state in onRestoreInstanceState or in onCreate.
To restore state of WebView you may use cookies and sessions and save last opened url. When activity will be recreated just navigate WebView last saved url and process result from camera.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 1);
By seeing your code I can judge that your motto is to capture the image and use it later on.
This is a known bug, The solution is that you need to create a separate folder for your application and before capturing you need to be sure that file is created and the same path you are giving to camera intent
Uri uriSavedImage=Uri.fromFile(new File("/sdcard/seperate/newImage.png"));
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("output", uriSavedImage);
startActivityForResult(cameraIntent, 1);
Reference: image from camera intent issue in android
Maybe a stupid sugestion.
But since it's destroyed, it means the device was low on memory.
If the only annoyance is that the webview reloads, maybe you can solve this by caching the content?
For example in the onStop() method of you activity get the content of the webview and store it somewhere. temporary file, sqlite,... . and in onCreate check if there is a cache (and maybe how old it is) and if needed put that in the webview.
Tutorial to get html code from webview: http://lexandera.com/2009/01/extracting-html-from-a-webview/
If i m not wrong you are opening camera from device.Have you check that other app is not aquired the camera? you must acquire camera before starting camera activity may be some other app using camera instance.You must release the camera instance in on destroy or onstop method of activity so that next time it will available fr other app to use it or for your app to use.
i am creating an application.
and use device default camera to take picture.
using this
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_PICTURE);
in onActivityResult() method i call again above code and take picture again.
but i want to take multiple pictures at a time. is there any way to take picture automatically when camera is called by intent (not by creating custom camera activity).
By sending intent you just say to existing camera application that it start and allow user to take picture - you are completely on the mercy of this application. Some of them may contain some undocumented parameters allowing you to snap picture automcatically.
http://developer.android.com/guide/topics/media/camera.html#intent-image
If you like to have control, you shall code camera application yourself.
I suppose you have to write your own custom camera, as there is no extra in MediaStore class that would allow taking another picutre.