2017-11-20 3 views
1

Ich versuche, den Text + Bild in WhatsApp durch meine Anwendung zu teilen. Aber ich kann das Bild nicht teilen Nur Text wird geteilt. Der Bildbereich wird leer angezeigt.
Hier ist mein CodeBild und Text zusammen in WhatsApp teilen

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(); 
} 

mein Screenshot

Hier ist

enter image description here

mir jemand helfen?

Antwort

1

Vielleicht Problem in Ihrem URI .. Versuchen Sie, diese Antwort

Intent Code:

   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")); 

Bitmap zu URI-Code: (falls haben Datei URI diese überspringen)

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

Sie richtig sind .Vielen Dank – Rajkumar

Verwandte Themen