Android 后台人脸检测

Android Face Detection on the background

我正在制作一个应用程序,我想在其中检测用户的脸而不显示它。我使用标准 android api,即 android.hardware.Camera.faceDetection() 当前置摄像头看到人脸时,phone 会振动。我已经实现了这部分,现在我需要让这个应用程序在后台运行,所以它不应该在屏幕上显示预览。可能吗?

我建议您阅读“Services" and more precisely "IntentService”class。

它基本上允许您在 UI 线程之外,在后台运行的单独线程中执行应用程序。

以下代码适用于后台工作者。 您可以在 doInBackground() 中添加您的代码。 它将在后台执行您的所有进程。 希望对你有所帮助。

import javax.swing.JOptionPane;
import javax.swing.SwingWorker;

public class Background extends SwingWorker<Void, Void>{

    @Override
    protected void done(){
            //JOptionPane.showMessageDialog(null,"Process Done Successfully...","Successfull",JOptionPane.INFORMATION_MESSAGE);
    }

    @Override
    protected Void doInBackground() throws Exception {
        //Write your code here
        return null;    
    }
}