0

Ich bin mit Universal-Image-Loader und konnte Bilder von meiner App weiterleiten diesen Code WhatsApp mitFreigabe Bild auf whatsapp nach dem letzten Update am 22. gebrochen kann

public static void shareImage(Context context, File pictureFile, String text) { 
    Uri imageUri = Uri.parse(pictureFile.getAbsolutePath()); 
    Intent shareIntent = new Intent(); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text); 

    shareIntent.setType("image/*"); 
    context.startActivity(Intent.createChooser(shareIntent, "Share")); 
} 

Aber mit der jüngsten whatsapp Aktualisierung Mai 22.. Ich bekomme 'Das Dateiformat wird nicht unterstützt' Toast.

enter image description here

+0

So haben Sie versucht, Dateiformate zu ändern? – jonrsharpe

+0

meist meine App enthält jpg und png. Derselbe Code wurde früher verwendet. –

+0

Ja, und jetzt haben sie anscheinend die unterstützten Formate geändert, also * müssen Sie auch ändern *. – jonrsharpe

Antwort

0

Frühere Bildpräsentations- funktionieren würde mit

shareIntent.setType("image/*"); 

aber in dem aktuellen Update sind folgende Änderungen erforderlich für den Austausch von Bild auf whatsapp

public class ImageFileNameGenerator implements FileNameGenerator { 
    @Override 
    public String generate(String imageUri) { 
     String extension = imageUri.substring(imageUri.lastIndexOf(".")); 
     return String.valueOf(imageUri.hashCode() + extension); 
    } 
} 

Update Config

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 
     .defaultDisplayImageOptions(defaultOptions) 
     .diskCacheFileNameGenerator(new ImageFileNameGenerator()) 
     .build(); 
ImageLoader.getInstance().init(config); 

Bildpräsentations- Code

public static void shareImage(Context context, File pictureFile, String text) { 
    String imagePath = pictureFile.getAbsolutePath(); 

    Uri imageUri = Uri.parse(imagePath); 
    Intent shareIntent = new Intent(); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text); 

    String imageFileExtension = imagePath.substring(imagePath.lastIndexOf(".")); 

    shareIntent.setType("image/" + imageFileExtension); 
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    context.startActivity(Intent.createChooser(shareIntent, "Share")); 
}