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.
            Asked
            
        
        
            Active
            
        
            Viewed 79 times
        
    0
            
            
        - 
                    https://stackoverflow.com/questions/35859816/how-to-listen-new-photos-in-android – ADM Feb 19 '19 at 04:00
 - 
                    Maybe `ContentObserver` is what you are looking for. This answer might help https://stackoverflow.com/a/40066666/7976274 – ankuranurag2 Feb 19 '19 at 08:34
 - 
                    Thank you. I'll look into this – Aman Agarwal Feb 19 '19 at 11:55
 
2 Answers
0
            
            
        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.
        Lorence Hernandez
        
- 1,189
 - 12
 - 23
 
- 
                    This is what I am already doing. I need to know how can i add a trigger to the camera(dcim) folder so that my service fires whenever a new image is added to it. – Aman Agarwal Feb 19 '19 at 04:34
 
0
            
            
        There are currently no APIs for logging and monitoring camera activity, probably for privacy and security reasons
        Safu Harry
        
- 11
 - 4