आपको mCamera.take चित्र को AsyncTask (या थ्रेड) के भीतर से शुरू करना चाहिए, हालांकि AsyncTaks का आसान विकल्प है।
एक बहुत आसान कार्यान्वयन (जो निश्चित रूप से संशोधित किया जा सकता है) करने के लिए:
विधि चित्र लेने के लिए कहा जाता है
/**
* Execute the AsyncTask that will handle the preview of the captured photo.
*/
public void takePicture() {
TakePictureTask takePictureTask = new TakePictureTask();
takePictureTask.execute();
}
AsyncTask उपवर्ग
/**
* A pretty basic example of an AsyncTask that takes the photo and
* then sleeps for a defined period of time before finishing. Upon
* finishing, it will restart the preview - Camera.startPreview().
*/
private class TakePictureTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
// This returns the preview back to the live camera feed
mCamera.startPreview();
}
@Override
protected Void doInBackground(Void... params) {
mCamera.takePicture(null, null, mPictureCallback);
// Sleep for however long, you could store this in a variable and
// have it updated by a menu item which the user selects.
try {
Thread.sleep(3000); // 3 second preview
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
पिक्चरकॉलबैक फ़ील्ड
private PictureCallback mPictureCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File file = null;
// Check whether the media is mounted with read/write permission.
if (Environment.MEDIA_MOUNTED.equals(
Environment.getExternalStorageState())) {
file = getOutputMediaFile();
}
if (file == null) {
Log.d(TAG, "Error creating media file, check storage persmissions!");
return;
}
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(data);
fileOutputStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
तो, क्या वे इस ट्यूटोरियल में क्या कर रहे हैं बस गलत है? http://developer.android.com/training/camera/cameradirect.html मैं वास्तव में समझ नहीं पा रहा हूं कि वे पूर्वावलोकन को पुनरारंभ कैसे करते हैं, लेकिन ऐसा लगता है कि AsyncTask या जो कुछ भी ... – Headcrab