2014-02-12 2 views
0

내 앱에는 카메라의 의도를 시작하고 캡쳐 한 이미지를 특정 경로에 저장하는 버튼이 있습니다. 사용자가 오른쪽 마크를 클릭하거나 카메라에서 옵션을 저장하면 캡처 된 이미지가 저장됩니다. 카메라에서 오른쪽 마크 또는 저장 옵션을 클릭하는 동시에 Camera Intent Launcher 작업의 onActivityResult()가 호출됩니다. 모두 잘 작동하지만 일부 장치에서는 버튼 클릭으로 카메라 의도가 시작되지만 이미지가 캡처 된 후 사용자가 저장 버튼을 클릭하면 카메라가 닫히지 않고 onActivityResult()으로 돌아 가지 않습니다. 카메라를 시작하려면이 의도를 사용하고 있습니다. 당신의 onActivityResult를에서일부 기기에서는 안드로이드 카메라가 작동하지 않습니다.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); 

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); 

    try { 
     intent.putExtra("return-data", true); 
     startActivityForResult(intent, PICK_FROM_CAMERA); 
    } 
    catch (ActivityNotFoundException e) 
    { 
     e.printStackTrace(); 
    } 

:

String path = Environment.getExternalStorageDirectory().toString(); 
Log.d("PATH", path); 
File myNewFolder = new File(path + "/it/Snapshots/"); 
myNewFolder.mkdirs(); 
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path + "/it/Snapshots/"+ic+".jpg"))); 
startActivityForResult(cameraIntent,1888); 

이 문제를 해결하기 위해 도와주세요 ... 나는 사전에

+1

당신은/it/snaphots이 쓰기 가능합니까 (또는 존재 하는가)? – Rob

+0

@Rob 그래도 쓸 수있는 것은 확실하지 않지만 .mkdirs()가 어떤 장치에서 어떤 방식 으로든주의를 기울여 작성한 것입니다. –

+1

외부 저장소가 없을 수 있습니다? – StuStirling

답변

1

사용이 코드를 여러분의 소중한 answers.Thanks 감사

if (intent != null && resultcode == RESULT_OK) 
      {    

        Uri selectedImage = intent.getData(); 

        String[] filePathColumn = {MediaStore.Images.Media.DATA}; 
        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
        cursor.moveToFirst(); 
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
        String filePath = cursor.getString(columnIndex); 
        Log.v("log","filePath is : "+filePath); 

        cursor.close(); 
        try 
        { 
         ExifInterface exif = new ExifInterface(filePath); 
         orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
         //Toast.makeText(getApplicationContext(), ""+orientation, 1).show(); 
         Log.v("log", "ort is "+orientation); 

        } 
        catch (IOException e) 
        { 
         e.printStackTrace(); 
        } 

        if(bmp != null && !bmp.isRecycled()) 
        { 
         bmp = null;    
        } 

        File f = new File(filePath); 

        if (orientation==6) 
        { 
         Matrix matrix = new Matrix(); 
         matrix.postRotate(90); 
         bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); 
        } 
        else if (orientation==8) 
        { 
         Matrix matrix = new Matrix(); 
         matrix.postRotate(270); 
         bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); 
        } 

        else if (orientation==3) 
        { 
         Matrix matrix = new Matrix(); 
         matrix.postRotate(180); 
         bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); 
        } 

        else if (orientation==0) 
        { 
         Matrix matrix = new Matrix(); 
         matrix.postRotate(0); 
         bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); 
        } 



      } 
      else 
      { 
       Log.v("log", "Photopicker canceled");   
      } 
+0

귀중한 답변을 주셔서 감사합니다 ... 외부 저장소에 문제가 있음을 확인했습니다. 외부 저장소가 없어서 작동하지 않는 이유가 무엇인지 ... 도와 주실 수 있습니까? 내부 디렉토리를 만드는 방법 기억 –

관련 문제