Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the image from camera without using camera app (via a service)

I need to create a service application which always looking and retrieve imaging file from if any new image taken from build in camera application.

1)My service needs to watching and taking the image from if new image was taken from build in camera application

how can we obtain the image path or image data in my service.

like image 276
Ramesh S Avatar asked Sep 08 '12 13:09

Ramesh S


People also ask

How do I take an image in the background without the camera app?

You can do that using CameraX. It is used to create your own camera app so you can do that by just omitting the preview part. Go to the below link for a small tutorial on cameraX https://developer.android.com/codelabs/camerax-getting-started#0 and you can just copy paste the code. For androidx.

How do I get photos from my camera to my Android phone?

This is done as follows: Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.

Is there a way to take a picture and find out what it is?

You can learn more about an image or the objects around you with Google Lens. For example, you can take a photo of a plant and use it to search for info or other similar images.


2 Answers

manifest code:

 <receiver android:name=".pictureReceiver" >
        <intent-filter android:priority="10000" >
           <action android:name="com.android.camera.NEW_PICTURE"/>
      <data android:mimeType="image/*"/>
        </intent-filter>
</receiver>

onReceive Code:

@Override
    public void onReceive(Context arg0, Intent arg1) {
           String selectedImageUri = arg1.getData().getPath();
           Log.d("TAG", "Received new photo:::"+selectedImageUri );
               Log.d("TAG","file Path"+getRealPathFromURI(arg1.getData(),arg0));
    }
 public String getRealPathFromURI(Uri contentUri,Context context)
        {
            try
            {
                String[] proj = {MediaStore.Images.Media.DATA};

                Cursor cursor =  context.getContentResolver().query(contentUri, proj, null, null, null);
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            }
            catch (Exception e)
            {
                return contentUri.getPath();
            }
        }
like image 109
K.Muthu Avatar answered Oct 12 '22 00:10

K.Muthu


FYI it is recommended to listen to the official broadcast since ICS API level 14: http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE. So filter for "android.hardware.action.NEW_PICTURE", and use "com.android.camera.NEW_PICTURE" in addition only if you need to support pre-ICS as well.

like image 45
Alan N Avatar answered Oct 12 '22 01:10

Alan N