2014-12-19 6 views
0

내 앱에 약 10 개의 이미지가 있으며 서버에서 다운로드 할 수없는 드로어 블 레졸루션으로되어 있습니다.내부 저장 장치에 저장하여 드로어 블에서 이미지 공유

이 이미지를 공유해야합니다.

나는 다음과 같은 해결책을 가지고있다 : 드로어 블을 파일로 변환하고, 저장하고, 폴더에서 파일을 공유한다.

SD 카드를 가지고있을 때 외부 저장 장치로 Everething이 정상입니다. 하지만 Nexus 5를 사용할 때 (예 : 내부 저장소) 일부 파일은 저장되지만 비공식 형식이므로 공유하지 않습니다.

내부 저장 또는 드로어 블에서 공유로 도와주세요.

private void shareit() 
    { 

     Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.son); 

     Intent share = new Intent(Intent.ACTION_SEND); 
     share.setType("image/jpeg"); 
     ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
     icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 

     File f;    

     String state = Environment.getExternalStorageState(); 
     if (Environment.MEDIA_MOUNTED.equals(state)) { 
      // We can read and write the media 
      f=new File(Environment.getExternalStorageDirectory() + File.separator + "son.jpg"); 
     } 
     else{ 
      f = new File(getActivity().getApplicationContext().getCacheDir(), "son.jpg"); 
      if(f.exists()){ 
       Log.i("imageExistsInternal", "file is complete"); 
      } 
     } 
     if(!f.exists()) 
      f.mkdir(); 
     share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); 
     startActivity(Intent.createChooser(share, "Share Image")); 
    } 
+0

여러 문제와 같이 변경해야합니다. 모두 고정 돼있어. 질문, 대답 및 대화를 읽습니다. http://stackoverflow.com/questions/27101881/how-to-always-save-image-with-new-name-and-delete-previouse-one-android – hasan83

+0

가 사용하려고했으나 외부 저장소에서만 작동합니다. – tadvas

답변

0

위의 코드에서 이미지를 파일에 쓰지 않았습니다. 이미지가 없으면 디렉토리가 만들어져 형식이 잘못되었습니다.

if(!f.exists()) 
     f.mkdir(); 

당신은 공유 이미지에서이

if (!f.exists()) { 
     FileOutputStream outputStream = null; 
     try { 
      outputStream = new FileOutputStream(f); 
      outputStream.write(bytes.toByteArray()); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } finally { 
      if (outputStream != null) { 
       try { 
        outputStream.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 
    } 
+0

unforunatuly, 그것은 나에게 도움이되지 않습니다. 어쩌면 다른 아이디어일까요? – tadvas