2012-08-12 6 views
2

Activity 사용자는 raw 폴더의 이미지를 공유 할 수 있습니다.Android : 원시 폴더에서 이미지 공유. 잘못된 이미지 공유

원시 폴더에는 알파벳순으로 이름이 지정된 70 개의 이미지가 있습니다. 첫 번째 문자는 R.raw.recipe01이고 마지막 문자는 R.raw.recipe70입니다.

이미지를 얻으려면 intBundle에서 공유하고 이미지를 raw 폴더에서 접근 가능한 파일로 복사하는 방법이 있습니다.

ActionBarMenuItemstartActivity(createShareIntent());으로 전화를 걸면 정상적으로 작동합니다.

문제

비중 intent 항상 Bundle에서 int이 exmaple R.raw.recipe33에 대한 이미지를 경우에도 이미지로 R.raw.recipe01을 선택합니다.

아래 코드를 공유했습니다. 아무도 내가 잘못하고있는 것을 발견 할 수 있습니까?

CODE :

private int rawphoto = 0; 
private static final String SHARED_FILE_NAME = "shared.png"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    Bundle bundle = getIntent().getExtras(); 
    rawphoto = bundle.getInt("rawphoto"); 
    int savedphoto = rawphoto; 

    // COPY IMAGE FROM RAW 
    copyPrivateRawResourceToPubliclyAccessibleFile(savedphoto); 


private Intent createShareIntent() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("image/*"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, "IMAGE TO SHARE: "); 
    Uri uri = Uri.fromFile(getFileStreamPath("shared.png")); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 

    return shareIntent; 
} 


private void copyPrivateRawResourceToPubliclyAccessibleFile(int photo) { 

    System.out.println("INT PHOTO: " +photo); 

    InputStream inputStream = null; 
    FileOutputStream outputStream = null; 
    try { 
     inputStream = getResources().openRawResource(photo); 
     outputStream = openFileOutput(SHARED_FILE_NAME, 
       Context.MODE_WORLD_READABLE | Context.MODE_APPEND); 
     byte[] buffer = new byte[1024]; 
     int length = 0; 
     try { 
      while ((length = inputStream.read(buffer)) > 0) { 
       outputStream.write(buffer, 0, length); 
      } 
     } catch (IOException ioe) { 
      /* ignore */ 
     } 
    } catch (FileNotFoundException fnfe) { 
     /* ignore */ 
    } 

    finally { 
     try { 
      inputStream.close(); 
     } catch (IOException ioe) { 

     } 
     try { 
      outputStream.close(); 
     } catch (IOException ioe) { 

     } 
    } 

} 
+1

왜 Context.MODE_APPEND입니까? 그 거기에 왜 –

+0

는 JoelSjögren @ 나도 몰라,하지만 난 그것을 제거했고 지금은 작동합니다. 감사! 답변을 받으실 수 있도록 의견을 보내주십시오 :-) – tiptopjat

+0

이 질문은 저의 답변입니다. 어떻게 원시 폴더에서 이미지를 공유 할 수 있습니다. 좋은 부도 !!! –

답변

1

이 이미 존재하는 경우 파일을 덮어 가도록 (듯이) Context.MODE_APPEND를 제거합니다.

관련 문제