【问题标题】:Image capture in Android automaticallyAndroid中的图像自动捕获
【发布时间】:2012-06-03 06:45:23
【问题描述】:

有没有办法使用下面的代码自动拍照,即根本没有按钮点击。不久之后,图像可以自动拍摄并存储在 SD 卡上。

protected void startCameraActivity() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(file_name)));
    startActivityForResult(intent, 1);
    finish();
}

【问题讨论】:

    标签: android android-layout android-intent android-emulator


    【解决方案1】:

    您可以根据您的要求将TimerTimerTask 类一起使用。只需研究以下代码并根据您的使用情况进行修改。

    import java.util.Timer;
    import java.util.TimerTask;
    
    class MyTimerTask extends TimerTask 
    {
      public void run() 
      {
          // Put your camera capturing and photo saving code here
      }
    }
    
    public class MainClass 
    {
      public static void main(String args[]) 
      {
        MyTimerTask myTask = new MyTimerTask();
        Timer myTimer = new Timer();
    
        /*
         * Set an initial delay of 15 second, then repeat every 10 second.
         */
    
        myTimer.schedule(myTask, 15000, 1000);
      }
    }
    

    【讨论】:

      【解决方案2】:

      不,一旦您启动了一个 Intent,您就真的无法控制您启动的 Activity(假设它不是您自己编写的)。在您的情况下,您必须制作自己的 Activity 并使用 Camera API。

      查看本教程:

      http://marakana.com/forums/android/examples/39.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-26
        • 1970-01-01
        • 2015-07-18
        • 1970-01-01
        • 2013-03-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-29
        相关资源
        最近更新 更多