简体   繁体   English

我只想在android中单击新图片时启动服务。 我该怎么做?

[英]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. 我只想从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. 当前,我正在运行一个后台任务,该任务每3秒运行一次,以检查是否单击了新图片。

You can have tracks for image clicks then check those tracks every 3 seconds. 您可以为图像单击提供音轨,然后每3秒检查一次这些音轨。

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,可能出于隐私和安全原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是Android新手。 我希望仅在服务启动时使用android服务来阻止通话 - I am new to android. I wish to use android service for blocking call only when the service is started 单击选项卡后如何启动新活动? - How do I start a new activity when a tab is clicked? 我想创建一个“全局”屏幕唤醒侦听器,该侦听器在所有活动中都保持活动状态。 - I want to create a “global” screen wake listener that stays active in all activities.. how do I go about doing this? 我如何进行onTouchListener,允许在android上同时按下两个按钮 - How do I go about doing an onTouchListener that allows pressing two buttons at the same time on android 我该如何做这个文件路径? - how do i go about doing this file path? 我想单击另一个活动吗? - I want to start another activity when it is clicked? 如何在新线程中启动服务? - How do I start a service in a new thread? 我在android中定义动作栏。 如何为每个操作添加新操作和点击侦听器? - I am defining actionbars in android. How do I add new actions and on click listener to each action? 在 Android java 中单击导航项时如何启动 n 个新活动 - How i can start n new activity when a Navigation item is clicked in Android java 我如何在Android中启动服务 - how do i start a service in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM