简体   繁体   中英

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

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.

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.

当前没有用于记录和监视摄像机活动的API,可能出于隐私和安全原因

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM