2017-11-20 3 views
1

내 응용 프로그램을 통해 whatsapp에 텍스트 + 이미지를 공유하려고합니다. 하지만 이미지를 공유 할 수 없으며 텍스트 만 공유됩니다. 이미지 영역은 공백으로 표시됩니다. 여기
내 코드 여기whatsapp에서 이미지와 텍스트를 함께 공유하십시오.

Uri uri = Uri.fromFile(new File(fname)); 
Intent share = new Intent(); 
share.setAction(Intent.ACTION_SEND); 
share.setPackage("com.whatsapp"); 
share.putExtra(Intent.EXTRA_TEXT,ci.description); 
share.putExtra(Intent.EXTRA_STREAM,uri); 
share.setType("image/*"); 
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
try { 
    context.startActivity(share); 
}catch (Exception what){ 
    Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show(); 
} 

내 스크린 샷이 사람이 나를 도울 수

enter image description here

이다?

   Intent i = new Intent(Intent.ACTION_SEND); 
        i.setPackage("com.whatsapp"); 
        i.setType("image/*"); 
        i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(context, bitmap, id)); 
        i.putExtra(Intent.EXTRA_TEXT, text); 
        context.startActivity(Intent.createChooser(i, "Share News")); 

비트 맵 URI 코드 :

답변

1

어쩌면 당신의 URI의 문제는 ..이 답변을

의도 코드를 사용해보십시오 당신이 옳다

public Uri getLocalBitmapUri(Context context, Bitmap bmp, String id) { 
    Uri bmpUri = null; 
    try { 
     if (id == null) { 
      id = String.valueOf(System.currentTimeMillis()); 

     } 
     File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + id + ".png"); 
     FileOutputStream out = new FileOutputStream(file); 
     bmp.compress(Bitmap.CompressFormat.PNG, 90, out); 
     out.close(); 
     bmpUri = Uri.fromFile(file); 
    } catch (Exception e) { 
     Log.e(TAG, "getLocalBitmapUri: ", e); 
    } 
    return bmpUri; 
} 
+1

을 (있는 경우 파일 URI이를 건너) .고맙습니다 – Rajkumar

관련 문제