2017-11-20 11 views
1

私のアプリケーションを通じて、whatsappでtext + imageを共有しようとしています。 しかし、画像を共有することはできません。テキストは共有されています。画像の領域は空白で表示されます。ここ
は、ここに私のコード画像とテキストを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

で誰も私を助けることができますか?

答えて

1

あなたのURIでたぶん問題..

この回答を試してみてください意向コード:

   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コードへのビットマップ:(ファイル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

あなたが正しいです。ありがとうございました – Rajkumar

関連する問題