tjvantoll / nativescript-social-share

♻️ A NativeScript plugin for using the iOS/Android social sharing widgets
MIT License
94 stars 48 forks source link

Is there any way to share an image together with text? #68

Open odedBartov opened 3 years ago

nicolaric commented 3 years ago

Would also like to see that!

odedBartov commented 3 years ago

Would also like to see that!

I modified the original code and now it works. In node_modules => nativescript-socail-share => social-share.android.js Replace the function "shareImage" with the following:

function shareImage(image, subject) {
    numberOfImagesCreated++;
    context = application.android.context;
    var intent = getIntent("*/*");
    var stream = new java.io.ByteArrayOutputStream();
    image.android.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, stream);
    var imageFileName = "imageNum" + numberOfImagesCreated + ".jpg";
    var newFile = new java.io.File(context.getExternalFilesDir(null), imageFileName);
    var fos = new java.io.FileOutputStream(newFile);
    fos.write(stream.toByteArray());
    fos.flush();
    fos.close();
    var shareableFileUri;
    var sdkVersionInt = parseInt(platform.device.sdkVersion);
    if (sdkVersionInt >= 21) {
        shareableFileUri = FileProviderPackageName.FileProvider.getUriForFile(context, application.android.nativeApp.getPackageName() + ".provider", newFile);
    }
    else {
        shareableFileUri = android.net.Uri.fromFile(newFile);
    }
    intent.putExtra(android.content.Intent.EXTRA_STREAM, shareableFileUri);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, subject);
    share(intent, subject);
}

You can just add another one for share with text instead of overriding the old one. Notice that you will have to also update the interface for the new function