2017-08-25 2 views
0

Je veux partager l'image via shareIntent. Mon code est donné ci-dessous:Impossible de partager l'image dans Gmail et Instagram

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType("image/*"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(list.get(position).getFilePath())); 
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sending from myApp");//gmail-subject 
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Image 1234");//gmail-body 
shareIntent.putExtra(Intent.EXTRA_TITLE, "Image 1234"); 
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
startActivity(Intent.createChooser(shareIntent, "Share via")); 

Je suis en mesure d'envoyer l'image dans WhatsApp et Facebook mais pas dans Gmail ou Instagram.

Lorsque vous essayez de partager via Gmail il me montre

Can't attach file

et pour Instagram il me montre

Impossible de charger l'image

.

Y a-t-il autre chose à ajouter dans shareIntent?

Répondre

0
File file = new File(Environment.getExternalStorageDirectory() + File.separator + yourFile.getRouteFile()); 
         if (file.exists()) { 
          String fileExtension = FileExtension.getFileExtension(file); 
          Log.d(TAG, "fileExtension: " + fileExtension); 
          Uri uri = Uri.parse("file://" + file.getAbsolutePath()); 
          Intent share = new Intent(Intent.ACTION_SEND); 
          share.putExtra(Intent.EXTRA_STREAM, uri); 
          share.setType(fileExtension + "/*"); 
          share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
          context.startActivity(Intent.createChooser(share, "Share file")); 
         } 

extension de fichier get

public static String getFileExtension(File file) { 
     String name = file.getName(); 
     try { 
      return name.substring(name.lastIndexOf(".") + 1); 
     } catch (Exception e) { 
      return ""; 
     } 
    } 
+0

Cela fonctionne très bien. Mais il y a un problème: share.setType (fileExtension + "/ *"); en raison de cette ligne, il me montre une petite liste d'applications partageables par rapport à share.setType ("image/*"); – Kesha

+0

ne peut utiliser que l'image –

+0

également droit à la réponse –