Ich bin neu in cordova
. Arbeiten am Projekt ble device.So öffnen Sie Standard-Kamera und ein Foto automatisch in Android
Meine Forderung ist, sollte
- Klicken Sie zuerst auf ble Gerät die Kamera öffnen.
- nächste entsprechende Klicks, um Fotos zu machen.
AutomaticPhotoActivity.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.TextView;
public class AutomaticPhotoActivity extends Activity{
private Camera camera; // camera object
private TextView textTimeLeft; // time left field
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textTimeLeft=(TextView)findViewById(R.id.textTimeLeft); // make time left object
/* Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);*/
camera = Camera.open(0);
try {
SurfaceView view = new SurfaceView(this);
camera.setPreviewDisplay(view.getHolder()); // feed dummy surface to surface
SurfaceTexture st = new SurfaceTexture(MODE_PRIVATE);
camera.setPreviewTexture(st);
} catch (IOException e) {
e.printStackTrace();
}
}
Camera.PictureCallback jpegCallBack=new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// set file destination and file name
File destination=new File(Environment.getExternalStorageDirectory(),"myPicture.jpg");
try {
Bitmap userImage = BitmapFactory.decodeByteArray(data, 0, data.length);
// set file out stream
FileOutputStream out = new FileOutputStream(destination);
// set compress format quality and stream
userImage.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
// onclick off button wait for 5seconds then take phot
public void startTimer(View v){
// 5000ms=5s at intervals of 1000ms=1s so that means it lasts 5 seconds
new CountDownTimer(5000,1000){
@Override
public void onFinish() {
// count finished
textTimeLeft.setText("Picture Taken");
camera.takePicture(null, null, null, jpegCallBack);
}
@Override
public void onTick(long millisUntilFinished) {
// every time 1 second passes`enter code here`
textTimeLeft.setText("Seconds Left: "+millisUntilFinished/1000);
}
}.start();
}
}
ich ein Foto aufnehmen können diesen Code verwenden, aber ohne Standard-Kamera geöffnet. Wie man ein Foto macht, nachdem ich die Kamera geöffnet habe, ohne Oberflächen zu verwenden. Als ich mache alle meine Entwürfe in html css, kein xml. bitte hilf mir.
UPDATE
Die beiden Antwort Oberfläche benötigen view.In meinem Fall wurde unter Verwendung i app Standard-Kamera zu öffnen und um ein Foto aufzunehmen hat. Wie funktioniert Selfiestick?
in einfach: wie automatisch Foto von Standard-Kamera-App.
Mögliche Duplikat [Nehmen Sie ein Foto automatisch ohne Zutun des Benutzers] (http://stackoverflow.com/questions/9752730/take-a-photo-automatically-without-user-interaction) –
Doppelte Frage sieh dies [Nimm ein Foto automatisch ohne Benutzerinteraktion] (http://stackoverflow.com/questions/9752730/take-a-photo-automatisch-ohne-benutzer-interaktion) – FarshidABZ
Nein, diese Frage ist anders als diese Antworten.Ich will um ein Foto von der Standard-Kamera-App ohne Benutzerinteraktion zu machen. –