我可以做一个即使在关闭应用程序后也会在特定时间间隔运行的后台服务吗

Can I Make A Background Service That runs at certain intervals of time even after closing the Application

我正在推荐此应用程序 https://github.com/hzitoun/android-camera2-secret-picture-taker。 在这个应用程序中有两个 类(APictureCapturingService.java & PictureCapturingServiceImpl.java) 可以在没有预览的情况下拍照 这两个 类 可以转换为后台服务,永远不会死。

是否可以将摄像头捕获过程作为后台服务,如果可以,如何进行?

我不知道你是如何在你的 activity 中拍照的,但我可以指导你 运行 你的应用程序在后台,即使你关闭你的应用程序,你也可以 运行 每秒你的相机代码..

public class SampleService extends Service {

public SampleService() {
}


@Override
public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    return null;
}

@Override
public int onStartCommand(final Intent inten, int flags, int startId) {

    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {

            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {


                        // Make use your method here..

                }
            });
        }
    }, 5000, 2000);

    return super.onStartCommand(inten, flags, startId);
}



@Override
public void onCreate() {
    super.onCreate();
}}

并且您需要启动服务表单activity..

startService(new Intent(this, SampleService.class));

我用它来监控前台应用程序,它会工作..