1
我目前正在嘗試將相機集成到我的android應用中,並將照片保存在我的設備上;然而,當我拍照時,我無法繼續進行(應用程序有效,但相機拍攝凍結,意味着我可以拍攝另一張照片並返回,但無法確認)。我想知道你們是否可以提供幫助。請儘可能簡單地解釋這一點,因爲我對android編程非常新穎。感謝大家!相機在Android應用上死機
public class PhotoCapture extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count=0;
public static File newfile;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.photocapture);
Button capture = (Button) findViewById(R.id.takepicture);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ContextWrapper cw = new ContextWrapper(getBaseContext());
newfile = cw.getDir("test.jpg", Context.MODE_PRIVATE);
try {
newfile.createNewFile();
} catch (IOException e) {}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
uri = data.getData().toString();
Log.d("CameraDemo", "Pic saved");
Intent myview = new Intent(this, Finalpiece.class);
startActivity(myview);
}
}
}
似乎onActivityResult沒有運行:( – user2309668 2013-04-23 03:47:22
參考這裏: http://stackoverflow.com/questions/15248265/camera-intent-not-working-with-samsung-galaxy-s3/15287164#15287164 – Skynet 2013-04-23 04:05:18