How to open Share Dialog in Android

How to open Share Dialog for sharing image file in Android



private void openShareDialog(String filePath) {

        File file = new File(filePath);

        /**
         * Check for image available or not in phone
         */
        if (file != null && file.exists()) {

            Uri uri = Uri.parse("file://" + file.getAbsolutePath());
            Intent share = new Intent(Intent.ACTION_SEND);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            share.setType("image/*");
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            getContext().startActivity(Intent.createChooser(share, getContext().getString(R.string.lbl_share_ticket)));
        } else {
            Toast.makeText(getContext(), getContext().getString(R.string.error_file_not_exist), Toast.LENGTH_SHORT).show();
        }

    }

Comments