我想開發一個android應用程序,該應用程序可以自動使用照相機意圖拍攝照片,而無需用戶進行任何交互,但無法自動獲取觸發圖像捕獲操作的代碼。任何人的幫助??。這裏是我的代碼如何使用意圖自動捕獲圖像,而無需任何用戶交互
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pictureButton = findViewById(R.id.captureFront);
countDownTimer = new MyCountDownTimer(startTime, interval);
if (!timerHasStarted) {
countDownTimer.start();
timerHasStarted = true;
} else {
countDownTimer.cancel();
timerHasStarted = false;
// startB.setText("RESTART");
}
}
public void pictureCapture() throws IOException {
pictureButton.setEnabled(true);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File sampleDir = Environment.getExternalStorageDirectory();
try {
imagefile = File.createTempFile("image", ".jpeg", sampleDir);
} catch (IOException e) {
Log.e(TAG, "sdcard access error");
return;
}
takePicture(shutter, raw, postview, jpeg);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
public final void takePicture(Camera.ShutterCallback shutter,
Camera.PictureCallback raw, Camera.PictureCallback postview,
Camera.PictureCallback jpeg) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Image saved to:\n" + data.getData(),
Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
Toast.makeText(this, "Image cancelled", Toast.LENGTH_LONG)
.show();
} else {
// Image capture failed, advise user
Toast.makeText(this, "Image failed", Toast.LENGTH_LONG).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class MyCountDownTimer extends CountDownTimer {
public MyCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
@Override
public void onFinish() {
// text.setText("Time's up!, finishes");
countDownTimer.cancel();
try {
pictureCapture();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onTick(long millisUntilFinished) {
// text.setText("" + millisUntilFinished/1000);
}
}
};
這是一個很好的......但你能告訴我,開發人員可以控制捕獲圖像的事件,這有可能嗎? –
@YogeshSeralia,對不起,我不明白這個問題。 –
我想問你,當我打開任何相機應用程序,然後它要求用戶點擊按鈕捕捉圖像,但是我們可以用自拍杆控制捕捉事件嗎? –