samedi 16 mai 2015

Share Image, plain text and html text via Intent

I'm trying to implement a function to share some information. The app requires to send plain text, HTML-formatted text (links) and a picture. This should be possible through SMS, Gmail, Whatsapp, etc. So far I've tried the following code:

    public void shareInfo(){

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);

        // Name (String), Type (String), Direction (String) and Images(String-HTML)
        String text = name+ "<br />";
        text = text + type + "<br />";
        text = text + direction + "<br />";                     

        // Images (String-HTML links)                                   
        for(int cont = 0; cont < _urlThumbsImagenes.length; cont++){
            text = text + "<a href=" + "\'" + _urlThumbsImagenes[cont] + "\'>" + "Image " + cont + "</a>" + "<br />";
        }
        shareIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));
        shareIntent.setType("text/html");           

        // Image 
        Uri pathImage = (Uri) ivPortada.getTag();
        shareIntent.putExtra(Intent.EXTRA_STREAM, pathImagenPortada);
        shareIntent.setType("image/*");

        startActivity(Intent.createChooser(shareIntent, "Share Intent :D"));
    }

This works for me when the Gmail option is chosen, but does not work in any other choice to share. If the user chooses SMS or WhatsApp, only shows the image to send.

How I can implement the function so that information is shared completely independently of the chosen mode?

Thank you for your time.

Aucun commentaire:

Enregistrer un commentaire