저는 여전히 Android 개발에 익숙하지 않지만 제가 갈 때 배우는 중이며 좀 더 배우기 위해 수업을 듣고 있습니다. 몇 가지 일을하는 앱이 있지만, 내가 붙어있는 부분은 카메라를 다루고 사진을 찍는 것입니다. 아이디어는 앱이 카메라로 사진을 찍고 이미지를 ImageView의 "소스"로 설정한다는 것입니다. ImageView에 비트 맵을 사용하면이 작업을 정상적으로 수행 할 수 있습니다. 그러나 사용자는 카메라로 사진을 찍은 다음 저장하면 갤러리에서 사진을 응용 프로그램으로 가져올 수 있어야합니다. 내가 붙어있는 곳이야. 이 튜토리얼을 따라 설정하고 작동 시키지만 이상한 오류가 발생했습니다. https://developer.android.com/training/camera/photobasics.html전체 사진을 저장할 수 없습니다. Android
"미리보기 이미지 가져 오기"섹션까지 가져올 수 있었지만 이후에는 막혔습니다. 내 사진을 어떤 위치에 저장하지 않는 이유가 확실하지 않습니다.
가 말한다 코드입니다 :
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
과 내가 내가 내가 한 file_paths
라고 xml
라는 내 res
폴더에 폴더를 만들고 거기에 파일을 넣을 필요하다는 것을 깨달았다. 내가 어떤 도움을 크게
감사
내 (관련) 자바 코드를 감사
<Paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.example.android.postvu/files/pictures" />
</Paths>
을 넣어 어디 그건 :
String mCurrentPhotoPath;
private File createImageFile() throws IOException
{
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
static final int REQUET_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent()
{
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null)
{
File photoFile = null;
try
{
photoFile = createImageFile();
}
catch (IOException ex)
{ }
if (photoFile != null)
{
Uri photoURI = FileProvider.getUriForFile(this, "com.example.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUET_TAKE_PHOTO);
}
}
}
private void galleryAddPic()
{
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
내 Manifest.XML 파일 :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.postvu">
<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">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<uses-feature android:name="android.hardware.camera2"> </uses-feature>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"></activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
</manifest>
제목에 언급 된 오류는 어디에 있습니까? 오류와 관련된 logcat 스택 추적을 게시하십시오. 게다가 코드에서 예외 인'IOException' :'catch (IOException ex) {}'이 (가) 음소거됨을 알 수 있습니다. 어떤 이유로이 예외가 발생하면 결코 알 수 없기 때문에 이것은 나쁘다! 'catch' 블록 안에'Log.e ("TAG", "error", ex)를 넣으십시오. 아마도 그 오류가있을 것입니다. – pleft
죄송합니다. 제목을 변경하는 것을 잊었습니다. –
또한 게시 한 URL에서 샘플 응용 프로그램을 다운로드하고 다르게하고있는 내용을보고 수정하지 않는 이유는 무엇입니까? http://developer.android.com/shareables/training/PhotoIntentActivity.zip – pleft