2017-08-25 3 views
0

Ich möchte Bild über shareIntent teilen. Mein Code ist unten angegeben:Kann kein Bild in Google Mail und Instagram teilen

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")); 

Ich bin in der Lage Bild in WhatsApp und Facebook aber nicht in Gmail oder Instagram zu senden.

Beim Versuch, über Gmail zu teilen es zeigt mir

Can't attach file

und für Instagram es zeigt mir

Bild kann nicht

0 laden

.

Ist noch etwas hinzuzufügen in shareIntent?

Antwort

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")); 
         } 

get Dateierweiterung

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

Dies funktioniert gut. Aber es gibt 1 Problem: share.setType (fileExtension + "/ *"); aufgrund dieser Zeile zeigt es mir eine kleine Liste von gemeinsam nutzbaren Apps im Vergleich zu share.setType ("image/*"); – Kesha

+0

kann nur Bild –

+0

auch richtige Marke der Antwort verwenden –

Verwandte Themen