Image capture in Android automatically

2019-04-16 07:04发布

Is there any way to use the following code to take pictures automatically i.e. no button clicks at all. Just after sometime image can be taken automatically and stored on the SD card.

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();
}

2条回答
神经病院院长
2楼-- · 2019-04-16 07:15

You can use Timer & TimerTask Class together for your requirement. Just study the following code and modify it according to your usage.

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);
  }
}
查看更多
forever°为你锁心
3楼-- · 2019-04-16 07:33

No, once you start an Intent you really have no control over the Activity you start (assuming it's not one that you wrote yourself). In your case, you have to make your own Activity and use the Camera API.

Check out this tutorial:

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

查看更多
登录 后发表回答