2014-09-12 4 views
0

viber 또는 watzapp를 통해 이미지를 보내려고합니다. Whatsapp은 잘 작동하지만 viber는 항상 "선택한 파일 사용자가 지원되지 않거나 손상되었습니다. 다른 파일을 선택하십시오."라고 계속해서 말합니다. 어떤 생각이 잘못 됐어?Viber에서 이미지 보내기

여기

Uri uri = Uri.parse("android.resource://com.example.test/drawable/image_1"); 
       sharingIntent.setType("image/jpg"); 
       sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); 
       startActivity(Intent.createChooser(sharingIntent, "Share image using")); 

답변

1
int checkExistence = getResources().getIdentifier("image_"+position, "drawable", getPackageName()); 
       Bitmap bitmapToShare = BitmapFactory.decodeResource(
         getResources(), checkExistence); 
       File pictureStorage = Environment 
         .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
       File noMedia = new File(pictureStorage, ".nomedia"); 
       if (!noMedia.exists()) 
        noMedia.mkdirs(); 
       File file = new File(noMedia, "meme_shared_image.png"); 
       if (saveBitmapAsFile(bitmapToShare, file)) { 
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file)); 
        shareIntent.setType("image/jpeg"); 
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
        startActivity(Intent.createChooser(shareIntent, "Share image using")); 
       } 
       else 
       { 
        Toast.makeText(MainActivity.this, "Sending Error", Toast.LENGTH_LONG).show(); 
       } 

      } 

      private boolean saveBitmapAsFile(Bitmap bitmapToShare, File file) { 
       FileOutputStream out; 
       try { 
        out = new FileOutputStream(file); 
        bitmapToShare.compress(Bitmap.CompressFormat.JPEG, 90, out); 
        return true; 
       } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
        return false; 
       } 
      } 

고정 ..이 시간에 다른 어떤 일을 도울 희망 내 코드입니다. how to share drawable image via viber and google hangout? 이것은 나에게 도움을 주었다.