这里有很多关于如何在android中的外部存储上创建文件的信息,将uri传递给ACTION_IMAGE_CAPTURE,然后将图像保存在那里.
但是,我想在Application的私有存储(有时称为内部存储)中创建一个文件,并将该文件uri传递给ACTION_IMAGE_CAPTURE,但Camera intent在onActivityResult中返回RESulT_CANCELED.
我该怎么办?
private voID checkWhetherCameraIsAvailableAndTakeAPIcture() { // Check wether this device is able to take pictures if (PhotoHandler.isIntentAvailable(a, MediaStore.ACTION_IMAGE_CAPTURE)) { System.gc(); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); file imagefile = null; try { if(a.application.user.isPublishImagesTogallery()){ imagefile = a.application.photoHandler.createImagefileOnExternalStorage(); } else { imagefile = a.application.photoHandler.createImagefileOnInternalStorage(); } imagePath = imagefile.getabsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromfile(imagefile)); } catch (IOException e) { e.printstacktrace(); imagefile = null; imagePath = null; } startActivityForResult(takePictureIntent, Preferences.REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA); } else { // Notify the user that their device is unable to take photos a.application.toastMaker.toastLong(ErrorMessages.DEVICE_UNABLE_TO_TAKE_PHOTOS); }} // End of checkWhetherCameraIsAvailableAndTakeAPIcturepublic file createImagefileOnInternalStorage() throws IOException { return createTempfileOnGivenLocation(); } private String imagefilename() { return filenamePrefix + Calendar.getInstance().getTimeInMillis(); } private file createTempfileOnGivenLocation() throws IOException { file imagefile = file.createTempfile(imagefilename(), filenameSuffix, context.getfilesDir()); setimagePathTemporary(imagefile.toString()); return imagefile; }@OverrIDepublic voID onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Preferences.REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA) { if (resultCode != Activity.RESulT_CANCELED) { handlePhotoTakenWithCamera(); } else { // ONACTIVITYRESulT Returns Here! new file(imagePath).delete()) } } else if (requestCode == Preferences.REQUEST_CODE_PICK_IMAGES_FROM_galLERY) { if (resultCode != Activity.RESulT_CANCELED) { handlePhotosPickedFromgallery(data); } }} // End of onActivityResult
解决方法:
每个应用程序的内部存储都是私有的Camera App无法访问应用程序的内部存储.在内部存储中获取图像的最佳方法是.
1)在app内使用自己的相机拍摄图像
要么
2)使用相机意图拍摄图像以捕获将图像保存到外部存储器的图片. onActivityResult将图像复制到应用程序的内部存储并从外部存储中删除.复制文件的代码可以在这个答案中找到. https://stackoverflow.com/a/4770586/4811470
总结以上是内存溢出为你收集整理的android – 从Camera保存图像将图片意图保存到应用程序私有存储全部内容,希望文章能够帮你解决android – 从Camera保存图像将图片意图保存到应用程序私有存储所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)