I am trying to attach image from my gridview to gmail or facebook,but whenever i tried to attach my app got crash,and i am getting following error with nullpointer exceptio
This is what worked for me perfectly.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.image_to_share);
startActivity(Intent.createChooser(shareIntent, "Share Image"));
But I will always recommend to decode a Bitmap from this resource, save it as a File in the storage and then use that file. A more reliable way this directly using from the resources.