-1

I watch many Questions and answer on stack overflow but i can't find my problem solution. I try to get captured image directly from camera and give to my background task for edit image and then save to it's original place.

My code is:

manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    String action = intent.getAction();
    final Handler handler = new Handler();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                manager.registerAvailabilityCallback(new CameraManager.AvailabilityCallback() {
                    @Override
                    public void onCameraAvailable(String cameraId) {
                        super.onCameraAvailable(cameraId);

                    }

                    @Override
                    public void onCameraUnavailable(String cameraId) {
                        super.onCameraUnavailable(cameraId);
                        //Do your work
                        camera.takePicture(myShutterCallback,
                                myPictureCallback_RAW, myPictureCallback_JPG);

                        myShutterCallback = new Camera.ShutterCallback(){

                            @Override
                            public void onShutter() {
                                // TODO Auto-generated method stub
                                Toast.makeText(context, "Shutter Clicked", Toast.LENGTH_SHORT).show();

                            }};

                        myPictureCallback_RAW = new Camera.PictureCallback(){

                            @Override
                            public void onPictureTaken(byte[] arg0, Camera arg1) {
                                // TODO Auto-generated method stub
                                Toast.makeText(context, "Raw Callback", Toast.LENGTH_SHORT).show();
                            }};

                        myPictureCallback_JPG = new Camera.PictureCallback(){

                            @Override
                            public void onPictureTaken(byte[] arg0, Camera arg1) {
                                // TODO Auto-generated method stub
                                Toast.makeText(context, "Image Captured", Toast.LENGTH_SHORT).show();
                                Bitmap bitmapPicture
                                        = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
                            }};
                        Toast.makeText(context, "Available Camera", Toast.LENGTH_SHORT).show();
                    }

                },handler);
            }
tj2611
  • 317
  • 1
  • 14

1 Answers1

0

Change return value START_STICKY in onStartCommand method

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
       Toast.makeText(this, "Start", Toast.LENGTH_SHORT).show();
       receiver = new CameraEventReceiverr();
       iFilter = new IntentFilter(Intent.ACTION_POWER_CONNECTED);
       iFilter.addAction(Intent.ACTION_CAMERA_BUTTON);
       iFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
       registerReceiver(receiver, iFilter);
       return START_STICKY;
    }
Gautam Surani
  • 1,136
  • 10
  • 21
  • still not work this time before open camera i close my app then remove charger when no response and then i reopen app then service start. – tj2611 Jun 15 '18 at 09:36