I'm using ActivityResultContracts to capture images, is there any way by which I can launch my front camera by default?
As per the documentation it is possible to pass extra data by overriding createIntent method, can I use that here?
It seems to be possible by using Intent but is there any way to achieve this using ActivityResultContracts?
Related
I need to open camera and take picture then get the result as file path and save it somewhere .In activity it is simple but in RecyclerView its a little bit hard to do I guess
its a nested RecyclerView by the way ,may not be that important but may be helpfull
Does any body know how to do this ?
Best way to do this is to use call back to parent activity and do all open camera related task there
In my apps, i need to pass image of image view from one activity to another. I know there are different kinds of way to pass image from activity to activity. But i want to know the best approach to do that. Previously i tried to pass image by getting the Bitmap of imageview from first activity then put in as putextra to the intent then extract the bitmap by getPercible to second activity. This was working good in Lollipop but getting error in Nougat. Now, i am trying to pass the bitmap as byteArray, but this is more unreliable than previous one. I don't know how to overcome this situation. Please help me in this context.
Where do you get your image from?
I would advise you to store it locally and only pass the path to it to the other activity. In this activity just retrieve the Bitmap again from your local storage.
I need to take a picture from camera where it goes to another activity where we have image view to show the picture taken through camera.My questions is how to pass image data through intents using camera2api?
In which method in camera2api i need to pass data for another activity?
You don't need Intent to pass image data from one Activity of your app to another. Actually, you cannot use Intent to pass a picture: there are restrictions on the size of the data bundled with Intent. So, you can use Intent extras to pass the path to an image, or some parameters extracted from the image. The Camera app uses intent extra("data") to return a thumbnail (very small) image.
Using the standard MediaStore.ACTION_IMAGE_CAPTURE Intent for latest devices which feature hardware.camera2 API is not different from the older devices that used the deprecated hardware.Camera.
You can employ some private Intent-based mechanism to communicate between activities of your app. In this case the consumer will probably pass necessary parameters to capture activity with startActivityForResult() and get the results in onActivityResult(). There are no methods in hardware.camera2 that can (or could be expected to) help you with these tasks.
I am writing an app that allows user to either take a picture with the camera
or choose an image in the gallery. I have a Fragment whose the layout displays
two boutons, depending on the button pressed I use intent either to start the
camera or open the Gallery. It works fine.
My purpose now is to do that with MVP. As I see things
my fragment is the View
the place from where images come from is the Model so in this case the models
would be getting images from the gallery or with the camera
a Presenter asks models to give him a picture and forwarding the image
to the fragment
The problem is model objects are Pojo classes and to retrieve an image from the
Camera or Gallery the class needs to implement startActivityForResult to retrieve
the photo taken/choosed.
How can I get image from camera/gallery with a class that is not a Fragment or
an Activity ?
How can I move code for camera/gallery in POJO class ?
Is it overall a good idea ? I did not find any MVP examples where retrieving
images was done out of a Fragment or an Activity ?
Note: Maybe is such an architecture possible with RxAndroid but I wish I could do that first without third party librairies.
Thanks for all your suggestion
How can I get image from camera/gallery with a class that is not a Fragment or an Activity ?
You have to do all this stuff from your presenter, not from your POJO class. Here you want to access an android resource, so pass the call back to the 'view-layer' from 'presenter-layer' and get response from system. Once the response is received in the onActivityResult method of Fragment/Activity, pass it into the presenter. cheers :)
I'm using this tab navigation: https://developer.android.com/samples/SlidingTabsColors/index.html
From the Android Developers site.
However I am unable to use a camera in any simple way, as the onActivityResult is never called. Apparently it works fine for fragments but presumably because the SlidingTabsColors example uses nested fragments (I think?) with the SlidingTabsColorsFragment creating (?) new fragments like this:
Fragment createFragment() {
return ContentFragment.newInstance(mTitle, mIndicatorColor, mDividerColor);
}
So my onActivityResult is never called. I have tried every variation of calling it that I could find suggested.
I've got some incredibly strung out code in the initial activity now that looks for the fragment and passes it the requestCode, resultCode and the data, all of which are off or null though (possibly another problem).
Is there a way I can have a smooth, tabbed navigation and be able to use the camera? I've not included any specific code as it's just the base code I mentioned, with a variety of attempts at simply calling a camera and saving an image. The camera opens and works fine, we just never get to onActivityResult. Is there perhaps another way to go about this?
Thanks for any help.