I want to start a service only when a new picture is clicked in android. How do I go about doing that?

83 Views Asked by At

I want to start a service only when a new picture is captured from the phone camera in android. How do I go about doing that? Currently, I am running a background task that runs every 3 seconds to check if a new picture has been clicked.

2

There are 2 best solutions below

1
Lorence Hernandez On

You can have tracks for image clicks then check those tracks every 3 seconds.

final boolean hasClicked = false;

new View.OnClickListener() { //image onclick listener
    hasClicked = true;
}



new Timer.schedule(new TimerTask() {
     if ( hasClicked ) {
         // start your service
     }

}, 3000, 3000);

If you need to track how many times the user clicked the image before the interval you can make a counter for it. be careful about the spam clicks.

0
Safu Harry On

There are currently no APIs for logging and monitoring camera activity, probably for privacy and security reasons