Activity
사용자는 raw
폴더의 이미지를 공유 할 수 있습니다.Android : 원시 폴더에서 이미지 공유. 잘못된 이미지 공유
원시 폴더에는 알파벳순으로 이름이 지정된 70 개의 이미지가 있습니다. 첫 번째 문자는 R.raw.recipe01
이고 마지막 문자는 R.raw.recipe70
입니다.
이미지를 얻으려면 int
Bundle
에서 공유하고 이미지를 raw
폴더에서 접근 가능한 파일로 복사하는 방법이 있습니다.
ActionBar
MenuItem
에 startActivity(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) {
}
}
}
왜 Context.MODE_APPEND입니까? 그 거기에 왜 –
는 JoelSjögren @ 나도 몰라,하지만 난 그것을 제거했고 지금은 작동합니다. 감사! 답변을 받으실 수 있도록 의견을 보내주십시오 :-) – tiptopjat
이 질문은 저의 답변입니다. 어떻게 원시 폴더에서 이미지를 공유 할 수 있습니다. 좋은 부도 !!! –