标签:match mfile jpg start manifest 解决 null media gen
private ArrayList<String> mImageList; private static final int REQUEST_CAMERA = 5; // 相机拍照标记 private static final int CAMERA_REQUEST_CODE = 1; /** * 拍照获取照片 */ protected void selectPicFromCamera() { if (!SDCardUtils.isSDCardEnable()){ //不存在sd卡 Toast.makeText(this,R.string.sd_disable,Toast.LENGTH_SHORT).show(); return; } //android 6.0之后需要动态申请权限 if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA}, CAMERA_REQUEST_CODE); } Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (cameraIntent.resolveActivity(this.getPackageManager()) != null) { tempFile = new File(FileUtils.createRootPath(this) + "/" + System.currentTimeMillis() + ".jpg"); LogUtils.e(tempFile.getAbsolutePath()); FileUtils.createFile(tempFile); Uri uri = FileProvider.getUriForFile(this, FileUtils.getApplicationId(this) + ".provider", tempFile); List<ResolveInfo> resInfoList = this.getPackageManager() .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; this.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //Uri.fromFile(tempFile) startActivityForResult(cameraIntent, REQUEST_CAMERA); } else { Toast.makeText(this, "打开相机失败", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){ if (tempFile != null){ mImageList.add(tempFile.getAbsolutePath()); } } }
android中调用相机拍照返回null的问题的终极解决办法
标签:match mfile jpg start manifest 解决 null media gen
原文地址:http://www.cnblogs.com/zhang-cb/p/6757583.html