Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Single method for multiple functionalities</p> <p>Code of <code>share(String nameApp,String imagePath,String message)</code> function:</p> <pre><code>public void share(String nameApp, String imagePath, String message) { try { List&lt;Intent&gt; targetedShareIntents = new ArrayList&lt;Intent&gt;(); Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/jpeg"); List&lt;ResolveInfo&gt; resInfo = getPackageManager() .queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Intent targetedShare = new Intent( android.content.Intent.ACTION_SEND); targetedShare.setType("image/jpeg"); // put here your mime // type if (info.activityInfo.packageName.toLowerCase().contains( nameApp) || info.activityInfo.name.toLowerCase().contains( nameApp)) { targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo"); targetedShare.putExtra(Intent.EXTRA_TEXT, message); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser( targetedShareIntents.remove(0), "Select app to share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); startActivity(chooserIntent); } } catch (Exception e) { Log.v("VM", "Exception while sending image on" + nameApp + " " + e.getMessage()); } } </code></pre> <p>For attaching image on gmail, facebook, twitter with text use below code.</p> <pre><code>File filePath = new File("your image path"); share("gmail", filePath.toString(),"your comment"); share("facebook", filePath.toString(),"your comment"); share("twitter", filePath.toString(),"your comment"); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload