yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
890 stars 131 forks source link

How To Share Pre Define Image Using Native Share #110

Closed Nameless77 closed 3 years ago

Nameless77 commented 3 years ago

Hello i am currently working on a sudoku game and want to publish it on play store.in this game i have added a sharing functionality(ex. when user press button a native share dialogue popped up and then when user click a perticular app to share then my game image automatically apper in that app(for example of whats app the image is automatically set))so how can i do this with native plugin.i already tried with resource folder(i put my image in resource folder but i cant get any image from resource folder).so can you please tell how to so this.

yasirkula commented 3 years ago

You can call Resources.Load<Texture2D>(texture path) and pass the returned Texture2D to AddFile.

Nameless77 commented 3 years ago

hello sir i am unable to share predefined image. as you mentioned i wrote some code here it is: `public void Click_Share() { StartCoroutine(TakeScreenShotAndShare()); } IEnumerator TakeScreenShotAndShare() { yield return new WaitForEndOfFrame();

    string filePath = Resources.Load<Texture2D>("Promo").ToString();
    new NativeShare().AddFile(filePath).SetSubject("Look at my Image").SetText("Hello world!")
    .SetUrl("https://play.google.com/store/apps/details?id=com.microsoft.sudoku").Share();
    // print(filePath);
}`

and this is the image which i want to share from resource folder : Screenshot 2021-05-03 133540 and on my android phone when i click on share button image was not loaded only text and url appear. so can you please suggest me something it will be a great help.

yasirkula commented 3 years ago
Texture2D image = Resources.Load<Texture2D>("Promo");
new NativeShare().AddFile(image).
Nameless77 commented 3 years ago

Thank you sir this time it's working I thought that the file path should be string.

On Mon, May 3, 2021, 1:48 PM Süleyman Yasir KULA @.***> wrote:

Texture2D image = Resources.Load("Promo");new NativeShare().AddFile(image).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yasirkula/UnityNativeShare/issues/110#issuecomment-831103337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMXDTTP53JYAHZCGII7KAWLTLZL5JANCNFSM437ODI4Q .

yasirkula commented 3 years ago

AddFile can take either a file path or a Texture2D (for convenience).