由於文檔描述在這裏Documentation我試圖通過意向訪問全尺寸圖像保存。據我瞭解,我已按照文檔中的每一步操作。現在我想知道如何訪問該文件onActivityResult()
。因爲該方法上的Intent
爲空。如何獲得在Uri後的全尺寸照片保存後
Activity.java
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.chathurangashan.cameraintent",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE) {
if (resultCode == RESULT_OK) {
if (data.hasExtra(MediaStore.EXTRA_OUTPUT)) {
Uri uri = (Uri) data.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
}
}
}
}
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chathurangashan.cameraintent">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.chathurangashan.cameraintent"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
file_path.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="my_images"
path="Android/data/com.example.chathurangashan.cameraintent/files/Pictures" />
</paths>
file_path.xml是資源文件夾下保存在 '資源'
PS:我知道我能得到的位圖中onActivityResult()
直接作爲文檔下,描述「獲取縮略圖」但它沒有返回原圖。它是拍攝圖像的低質量版本。
「它返回null intent onActivityResult」 - 您可能想編輯您的問題併發布整個Java堆棧跟蹤。請注意,'EXTRA_OUTPUT'是您在'ACTION_IMAGE_CAPTURE''Intent'上提供的值。它不是返回數據的一部分。 – CommonsWare
謝謝。編輯。 –