gpt4 book ai didi

java - Android上最近抓包文件事件拦截

转载 作者:行者123 更新时间:2023-11-30 01:58:47 24 4
gpt4 key购买 nike

我想做的只是添加带有最近捕获的文件名的日志行。不幸的是,应用程序由于以下指示的错误而失败。下面提供的堆栈中的代码和错误。

提前致谢

阿纳尔

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity {az.justx.justx/az.justx.justx.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference

private void interceptCameraButtonClick() {

Button cameraButton = (Button) findViewById(R.id.cam);

cameraButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
imagesFolder.mkdirs(); // <----
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File image = new File(imagesFolder, "AD_" + timeStamp + ".jpg");
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(imageIntent, 100);
}
}
);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

Log.i("Test", Integer.toString(resultCode));

if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Log.i("CALLED", "Image saved to:\n" +
data.getData());
Toast.makeText(this, "Image saved to:\n" +
data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}

}

最佳答案

不要求相机在传递给onActivityResult()Intent 中发回Uri。您已经知道 Uri 是什么,因为您将它放在 EXTRA_OUTPUT 中。您只需要使用该值。请务必将其包含在您保存的实例状态中,因为您的进程可能会在相机应用程序处于前台时终止。

关于java - Android上最近抓包文件事件拦截,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31809725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com