我有两项活动(A1,A2).A1调用A2,从A2调用相机意图,如下所示
launchIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
launchIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoPath);
startActivityForResult(launchIntent,CAMERA_REQUEST);
Run Code Online (Sandbox Code Playgroud)
它打开相机,我可以拍照.但是当我点击保存按钮(s3中的勾选按钮)时出现问题,我的onActivityResult没有被调用,而是调用了A2的onDestroy方法.我在onActivityResult fn中完成的逻辑很少.
我已经阅读了Stackoverflow中的一些关于此的帖子,但我无法从中得到有用的输出.我的第二个活动(A2)有我的清单
android:configChanges="keyboardHidden|orientation|locale"
android:screenOrientation="portrait
Run Code Online (Sandbox Code Playgroud)
注意:在HTC One X中我的onActivityResult fn被调用,但在我的S3中,第二个Activity(A2)被破坏了
Plz分享你对此的想法.提前致谢
我正在整合Facebook与Android,我想拍摄时,将其保存到SD卡,然后将其上传到Facebook.
这是我的代码:
photo_up=(Button)findViewById(R.id.camera_foto_button);
photo_up.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(PlaceScreen.this)) );
startActivityForResult(intent,CAMERA_REQUEST);
}
});
private File getTempFile(Context context){
//it will return /sdcard/image.tmp
final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
if(!path.exists()){
path.mkdir();
}
return new File(path, "image.png");
}
Run Code Online (Sandbox Code Playgroud)
和OnActivity结果
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case CAMERA_REQUEST:{
final File file = getTempFile(this);
try {
bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.fromFile(file) );
// do whatever you want with the …Run Code Online (Sandbox Code Playgroud)