通过SD卡的意图将图像发送到其他应用程序

时间:2017-02-07 07:43:32

标签: android android-intent share

我正试图通过意图将图像发送到其他应用程序...我正在从内部存储发送图像但我无法从我的SD卡分享...我如何从SD卡分享它。 ?

这是我的代码:

public void shareMultipleImages(View v) {
    String imagePath1 = Environment.getExternalStorageDirectory()
            + "SD card/fb images/" + "gujju.jpg";
    String imagePath2 = Environment.getExternalStorageDirectory()
            + "SD card/fb images/" + "zindgi.jpg";
    // Multiple Images' file objects
    File image1FileToShare = new File(imagePath1);
    File image2FileToShare = new File(imagePath2);
    // Get URI of Image's location
    Uri image1URI = Uri.fromFile(image1FileToShare);
    Uri image2URI = Uri.fromFile(image2FileToShare);
    ArrayList<Uri> imageUris = new ArrayList<Uri>();
    imageUris.add(image1URI); // Add your image URIs here
    imageUris.add(image2URI); // Add your image URIs here
    // Set the action to be performed i.e 'Send Multiple Data'
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    // Add the URIs holding a stream of data 
    sendIntent.putExtra(Intent.EXTRA_STREAM, imageUris);
    // Set the type of data i.e 'image/* which means image/png, image/jpg, image/jpeg etc.,'
    sendIntent.setType("image/*");
    // Launches the activity; Open 'Gallery' if you set it as default app to handle Image
    startActivity(sendIntent);
}

0 个答案:

没有答案