Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Native Share for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Mar 1, 2018.

  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,557
    Hey, Your plugin is great.

    I just wanted to ask incase you know, is there any way to share to just a single individual? Native sharing allows you to share too many but in my use case i want to restrict the user and only send to one recipient. I looked and native sharing plugin doesn't seem to do this, and I wouldn't really expect it to, i was just wondering if you know of any other methods or plugins I might be able to use to do that?

    Thanks again for the plugin.
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    You might have to use app-specific SDKs like Facebook SDK for this. But I don't really know any details about this topic.
     
  3. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,557
    Yeah, that's what I feared. I was hoping you could just set a max recipients variable in native code somewhere. :( Thanks though.
     
  4. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    @yasirkula . i have used the native image to gallery. It is working fine. I am using the below code.


    NativeGallery.SaveImageToGallery(tex, Application.productName + "Screenshots", name);
    Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(tex, Application.productName + " Captures", name));


    the image is saving twice in my gallery.

    In your script nativegallery.cs the below line is called twice. I think this is the reason for saving twice. so how can i avoid two times saving my image gallery..

    Code (CSharp):
    1.  
    2. NativeGallery.SaveImageToGallery(tex, Application.productName + "Screenshots", name);
    3.             Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(tex, Application.productName + " Captures", name));
    4.             var bytes = tex.EncodeToPNG();
    5.             File.WriteAllBytes(Application.dataPath + "/Gallery/fooya.png", bytes);  filePath = string.Format("{0}_Capture{1}_{2}.png", Application.productName, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
    6.  

    Code (CSharp):
    1. NativeGallery.SaveImageToGallery(tex, Application.productName + "Screenshots", name);
    2.             Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(tex, Application.productName + " Captures", name));
    3.             var bytes = tex.EncodeToPNG();
    4.             File.WriteAllBytes(Application.dataPath + "/Gallery/fooya.png", bytes);
    5.  
    6. Debug.Log( "SaveToGallery called successfully in the Editor" );
    7.  
    8. private static Permission SaveToGallery( string existingMediaPath, string album, string filename, MediaType mediaType, MediaSaveCallback callback )
    9.  
    10. private static Permission SaveToGallery( byte[] mediaBytes, string album, string filename, MediaType mediaType, MediaSaveCallback callback )
    11.     {
    can you give some suggestions...
     
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    Each time you call NativeGallery.SaveImageToGallery, the image will be saved to gallery. So, it is two saves: one to the Screenshots album and the other to the Captures album.
     
  6. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    @yasirkula thanks for your reply. In my mobile ...

    Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(tex, Application.productName + " Captures", name));


    i have removed this code. now it is saving once...

    Actually i have to crop the image... Whole screen is capturing .... I have tried many code for croping the image. . But not working fine. can you post some code... It is very helpful for all ... it boosts your sharing plugin...
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  8. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    @yasikula actually i dont want to add any plugin for solutions. I have tried unity screenshot partial area... but i did not get best solutions. ...i am trying .. if got i will post the code..
     
  9. Turkoz

    Turkoz

    Joined:
    Aug 16, 2015
    Posts:
    8
    Hi @yasikula, I have two questions:

    1- I know that it has been already asked but is there any way to check when the user come back to the app after sharing anything with te plugin, like a callback ?

    2- Is there any way to set the share on an specific app like gmail (to send a email) on both platforms IOS and Android ?

    Thanks! And really appreciate what you have done!
     
    yasirkula likes this.
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    1) There is no callback, sorry.
    2) Please see the FAQ on the main post.
     
  11. emilioeigler2

    emilioeigler2

    Joined:
    Sep 9, 2019
    Posts:
    4
    Hello, first tell you that your plugin is great!
    and I ask you a question, everything works perfect for me, but I can't share an audio file, I saw many possible solutions in many messages but I can't do it, could you explain it in detail if it's not too much trouble?
    a million thanks!
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    No additional setup needed for audio files, they should just work. You can try omitting SetText and SetSubject functions if you are using them. You can also try setting the mime parameter of AddFile as "audio/*".
     
  13. paintpaul

    paintpaul

    Joined:
    Mar 8, 2017
    Posts:
    19
    Hello everyone,
    I´m using Proguard. Where do I add -keep class com.yasirkula.unity.* { *; } ?
    Thank you!
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    paintpaul likes this.
  15. paintpaul

    paintpaul

    Joined:
    Mar 8, 2017
    Posts:
    19
    Thank you for your reply! Then it still was not possible to share the screenshot... The logcat said: Can´t find ContentProvider, share not possible! So I had to add the provider to the xml again. Now it´s working!
    Thank you very much!
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    In the latest versions of the plugin, the provider should automatically be added to the AndroidManifest at build time but regardless, happy to hear that all is well!
     
  17. SinDeSiecle

    SinDeSiecle

    Joined:
    Sep 30, 2017
    Posts:
    32
    Hi,

    Using this asset for an app. Just works with iOS out of box. But, on android no share windows opened. I get the following catlog debug:

    01-27 11:35:57.577 3030 3059 E Unity : at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

    01-27 11:35:57.577 3030 3059 E Unity : at [my app identifier, can't share here].UnityPlayer.nativeRender(Native Method)

    01-27 11:35:57.577 3030 3059 E Unity : at [my app identifier, can't share here].UnityPlayer.c(Unknown Source)

    01-27 11:35:57.577 3030 3059 E Unity : at [my app identifier, can't share here].UnityPlayer$e$1.handleMessage(Unknown Source)

    01-27 11:35:57.577 3030 3059 E Unity : at android.os.Handler.dispatchMessage(Handler.java:98)

    01-27 11:35:57.577 3030 3059 E Unity : at android.os.Looper.loop(Looper.java:168)

    01-27 11:35:57.577 3030 3059 E Unity : at com.unity


    What should I look at to fix to make it work with my setup?
     
  18. paintpaul

    paintpaul

    Joined:
    Mar 8, 2017
    Posts:
    19
    @yasirkula yes it´s only working with the manually added provider. Thank you for helping :)
     
    yasirkula likes this.
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    @SinDeSiecle If you are using ProGuard Minification, please see the corresponding FAQ entry in the main post.
     
  20. emilioeigler2

    emilioeigler2

    Joined:
    Sep 9, 2019
    Posts:
    4
    This is my code to share audio, will I be doing something wrong?

    filePath = Path.Combine(Application.streamingAssetsPath, "1.wav");
    new NativeShare().AddFile(filePath, "audio/*").Share();

    or
    new NativeShare().AddFile("Assets/Sounds/1.ogg", "audio/*").Share();
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  22. emilioeigler2

    emilioeigler2

    Joined:
    Sep 9, 2019
    Posts:
    4
    Now yes, it works perfect, thank you very much and sorry for the trouble!
     
    yasirkula likes this.
  23. SinDeSiecle

    SinDeSiecle

    Joined:
    Sep 30, 2017
    Posts:
    32
    Solved my problem by re-importing...
     
    yasirkula likes this.
  24. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Hi @yasirkula
    Thank you for your amazing plugin. But I have a question:
    I don't want to share on Twitter. Can I hide Twitter icon in list social apps?
     
    Last edited: Feb 6, 2020
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  26. Turkoz

    Turkoz

    Joined:
    Aug 16, 2015
    Posts:
    8
    Hi @yasikula:

    Is there any way to set multiple email adresses to send ?

    Thanks! And really appreciate what you have done!
     
    yasirkula likes this.
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    NativeShare doesn't support this feature, sorry.
     
  28. milamila

    milamila

    Joined:
    Nov 21, 2013
    Posts:
    16
    Hi, is it possiple to share to tik-tok?
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    If Tik-Tok has integration with native share dialog, then it should be possible. I haven't tried it out myself, though.
     
  30. milamila

    milamila

    Joined:
    Nov 21, 2013
    Posts:
    16
    Thank you, for such an immediate reply!
     
  31. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Hi @yasirkula
    I use NativeGallery and NativeShare together.
    But when I save image or video to device gallery and I want to share it but I don't how to get filePath in device gallery??
    Hope you answer soon. Thank you so much.
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    Fetching path is not possible, please see the FAQ: https://forum.unity.com/threads/native-gallery-for-android-ios-open-source.519619/. You need to keep a separate copy of the image in e.g. temporaryCachePath and share it instead. If you are using SaveImageToGallery with an existingMediaPath, then you can simply share the file at existingMediaPath since NativeGallery simply copies the file to Gallery, not moves it.

    EDIT: Corrected FAQ link.
     
    GaZnoDrone likes this.
  33. gmsunity3d

    gmsunity3d

    Joined:
    May 20, 2019
    Posts:
    1
    Hi yasirkula,

    is it possible add cc to email

    like this new NativeShare().AddFile(filePath).SetTarget(
    com.google.android.gm).SetCC("random@xyz.com")SetText(mBody).Share();
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    NativeShare doesn't have any e-mail specific functionalities, sorry.
     
  35. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Hi @yasirkula

    When I share on SNS, I want to change something like image I have attached below:

    1. This image "IMG_0141" I want to change "icon app".
    2. This image "IMG_0142" I want to text "456" auto show when I share.

    It's possible to do that? Hope for your answer soon!
    Thank you so much :)
     

    Attached Files:

  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    1. Looking at this topic, it sure seems possible. The accepted answer in that question makes the modification I've described in this Issue. However, this modification might break image sharing in some apps (it did for me a few years ago), so make sure to test the code on popular social apps.

    2. You can call the SetText function in conjunction with AddFile function but sharing a file together with a text is risky since some apps may omit either the text or the file from the shared content, unfortunately.
     
  37. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Thank you for your answer. I will try and tell you if it's worked :)
    But when I call the "SetText", for example: "456" then the text "HelloWorld"(in IMG_0141) is "456".
    I want to make separate text in "IMG_0141" is "Hello World!" and "IMG_0142" is "456".

    It's possible to do that? Hope for your answer soon!
    Thank you so much :)
     

    Attached Files:

  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  39. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    I am not sure if this was asked before, can mp4 files be shared too specifically to WhatsApp? I am planning to use the Native Gallery Asset and Native Share Assets.
     
  40. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    Been going through the post seems like it can be done assuming video file means mp4 files. Thank you.
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  42. KaanSerin113

    KaanSerin113

    Joined:
    Nov 17, 2012
    Posts:
    5
    Hi, Is there a way to verify whether the user actually shared somewhere, instead of pressing a share button and backing out?
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    There is no callback, no.
     
    KaanSerin113 likes this.
  44. KaanSerin113

    KaanSerin113

    Joined:
    Nov 17, 2012
    Posts:
    5
    Thanks anyway for the great asset and the quick response
     
    yasirkula likes this.
  45. interpretasyo

    interpretasyo

    Joined:
    Jun 18, 2019
    Posts:
    33
    Hi,

    Just want to ask what is the difference between the following in Facebook Messenger and in Facebook.
    NativeShare().SetText
    NativeShare().SetTitle
    NativeShare().SetSubject

    Just want to know before we deploy and test it. Thanks!
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    SetSubject should have no effect on Facebook, SetTitle sets the title of the share dialog on Android platform, i.e. the app selection dialog (has no effect on iOS), SetText actually sets the shared text. But it will probably not work in conjunction with AddFile, please see FAQ for more info about that.
     
  47. kushwaha03

    kushwaha03

    Joined:
    Dec 18, 2019
    Posts:
    38
    How can be shared only image for ios app
    NativeShare().AddFile(Path)
    .SetTarget("com.whatsapp").SetTitle("Share your photo")
    .Share();
    or
    NativeShare().AddFile(Path)
    .SetTarget("com.whatsapp")
    .Share();

    right??
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
  49. kushwaha03

    kushwaha03

    Joined:
    Dec 18, 2019
    Posts:
    38
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,584
    Not on iOS.
     
unityunity