我的应用使用 MediaStore.ACTION_IMAGE_CAPTURE Intent 拍照。问题是,在我按下快门按钮后但在显示允许我重新拍摄或接受照片的“确定”和“取消”按钮之前,应用程序会间歇性地崩溃。确定和取消按钮选择是意图的一部分,而不是我的代码,因此崩溃似乎不是由我的代码直接引起的。
应用程序刚刚关闭,没有显示错误消息,logcat 没有反应,cpu/网络/内存监视器突然停止并显示“监视器已禁用”。
private void dispatchTakePictureIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getPhotoFileUri(photoFileName));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
photoFileName 总是file:///storage/emulated/0/Android/data/com.companyname.appname/files/Pictures/AppName/myphoto.jpg
拍照后由此代码处理
private List<Bitmap> myImages;
enter code here
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Uri takenPhotoUri = getPhotoFileUri(photoFileName);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath(), options);
//Store image in memory
myImages.add(takenImage);
if (myImagesAdapter == null) {
myImagesAdapter = new MyImagesListViewAdapter(this, myImages);
GridView myListView = (GridView) findViewById(R.id.my_images_view);
myListView.setAdapter(myImagesAdapter);
myImagesAdapter.notifyDataSetChanged();
} else {
myImagesAdapter.notifyDataSetChanged();
}
} else { // Result was a failure
Toast.makeText(this, "Picture wasn't taken!", Toast.LENGTH_SHORT).show();
}
}
}
}
此外,这种情况似乎更频繁/仅在调试模式下(在 android studio 中按下错误)而不是在我运行它(按下播放按钮)时发生。
拍摄第一张照片时发生了这种情况,但在第二、第三和第四张照片中也发生了这种情况。
更新 1 当我将 logcat 更改为 ha No Filters 我得到这些行
09-06 22:30:26.961 990-1473/? I/WindowState: WIN DEATH: Window{296d6791 u0 com.mycompany.myapp/com.mycompany.myapp.MyFirstActivity}
09-06 22:30:26.965 990-1473/? D/InputDispatcher:窗口消失:Window{296d6791 u0 com.mycompany.myapp/com.mycompany.myapp.MyFirstActivity}
09-06 22:30:26.968 990-2174/? I/WindowState: WIN DEATH: Window{3ac0ee0b u0 com.mycompany.myapp/com.mycompany.myapp.MySecondActivity}
09-06 22:30:26.971 990-2174/? D/InputDispatcher:窗口消失:Window{3ac0ee0b u0 com.mycompany.myapp/com.mycompany.myapp.MySecondActivity}
09-06 22:30:27.059 990-1819/? I/ActivityManager:进程 com.mycompany.myapp (pid 8623) 已死亡
09-06 22:30:27.626 990-2174/? I/ActivityManager: 强制停止 com.mycompany.myapp appid=10170 user=0: from pid 9949
09-06 22:30:27.627 990-2174/? I/ActivityManager:强制完成活动 ActivityRecord{18ca1aa0 u0 com.mycompany.myapp/.MyFirstActivity t254}
09-06 22:30:27.631 990-2174/? I/ActivityManager:强制完成活动 ActivityRecord{15946ece u0 com.mycompany.myapp/.MySecondActivity t254}
09-06 22:30:27.666 2249-2249/? W/NearbyMessages:ClientAppContext:0P 标识符(com.mycompany.myapp)没有 0P 前缀(0p :)