1

有没有办法使用以下代码自动拍照,即根本没有按钮点击。不久之后,图像可以自动拍摄并存储在 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();
}
4

2 回答 2

2

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

看看这个教程:

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

于 2012-05-29T03:34:15.450 回答
1

您可以根据您的要求一起使用Timer& Class。TimerTask只需研究以下代码并根据您的使用情况进行修改。

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);
  }
}
于 2012-05-29T02:54:31.653 回答