Search Unity

  1. 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. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Please check logcat for any error messages. In addition, please share the relevant parts of your sharing script here.
     
  2. NewGame789

    NewGame789

    Joined:
    May 16, 2019
    Posts:
    15
    i didn't get an error in unity

    this is the sharing script

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class Urls : MonoBehaviour {


    public string RateUsUrl;

    public string ShareUrl;





    public void RateUs ()
    {
    Application.OpenURL (RateUsUrl);
    }


    public void Share ()
    {
    new NativeShare().SetText( ShareUrl ).Share();
    }


    }
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
  4. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    109
    at the and was an android problem, with another device all work GREAT!!

    THANK YOU A LOT MY SAVIOR!
     
  5. NewGame789

    NewGame789

    Joined:
    May 16, 2019
    Posts:
    15
    I found the problem is the space between "ShareUrl" .SetText( ShareUrl ) should be .SetText(ShareUrl)

    thank you so much for your help
     
  6. Vasilis-Mbakalis

    Vasilis-Mbakalis

    Joined:
    May 23, 2017
    Posts:
    16
    Hi! I want to ask a question, I have a created an app for android and iOS and i download some files from a server and i want the user to be able to open the download file.I was using openURL for this but it is not possible any more.Can your asset help me with that?
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    NativeShare doesn't have such functionality, sorry :/
     
  8. KRSBX

    KRSBX

    Joined:
    Nov 18, 2016
    Posts:
    10
    So, I import the plugin from the asset store and i copy the example code and i tried to run it in my phone but nothing happens. Any idea how to fix it? Currently using Unity 2019.1.7f1
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Did you attach the component (example script) to an object in your scene? If so, please check logcat or Xcode console for any meaningful error messages.
     
  10. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    8
    Hi, is it possible for this plugin to support sharing on LinkedIn?
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    If LinkedIn doesn't appear in the apps list, then try omitting subject/text/image from the shared content (e.g. try sharing only image or only text). It is possible that LinkedIn doesn't accept image+text sharing via native functions that NativeShare uses.
     
  12. Voloda2

    Voloda2

    Joined:
    Jan 7, 2017
    Posts:
    5
    NativeShare works only for iOS and don't work for android. What is wrong?


    Code (CSharp):
    1. var fileName = "stamps.pdf";
    2.         var pdfPath = Application.streamingAssetsPath + "/" + fileName;
    3.         if (System.IO.File.Exists(pdfPath)) {
    4.  
    5.             new NativeShare().AddFile(pdfPath).SetSubject("Марки").SetText("Марки").Share();
    6.         }
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
  14. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    8
    Thank you for this awesome plugin, it works for me at least. One more thing to know:

    Can I filter/limit the user on what they can share on? Eg: I wanted user to only able to share on facebook & twitter
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
  16. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    8
    It is possible to have a workaround for let say I wanted to share A content on Mail, and B content on Facebook, and C content on Twitter, etc
     
  17. kniger33

    kniger33

    Joined:
    Jul 14, 2018
    Posts:
    2
    Hi! I have a 2 little problems.
    1) If my app is locked by app locker(by password or fingerprint) and I try to share image, in my first try it will return me "error" or nothing to share. And in next try, when app to share is unlock, it works correctly.
    2) On some android devices not appear apps to share in my unity app, but in empty unity app with only native share it works good and shows all available apps.
    Thanks a lot.
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    @xuan_celestial It might be possible but I've no such experience, sorry.

    @kniger33 1) You mean e.g. locking WhatsApp with app locker and then sharing on WhatsApp, right? Does the Gallery app's native share sheet work properly, though? If so, please check logcat for any meaningful error messages (I'm assuming that the "error" message is displayed on screen). 2) So, you have two NativeShare-integrated apps and app 1's share sheet doesn't work on some Android devices but app 2's share sheet works on all Android devices, am I correct? If so, honestly, I'm not sure what the issue here would be.
     
  19. kniger33

    kniger33

    Joined:
    Jul 14, 2018
    Posts:
    2
    1) Thanks, I will try it.
    2) Not exactly. Both of apps are install on one Android device. In the case of empty app with NativeShare-integrated only it shows all available to share app, and in second case it doesnt. But on other device with same Android version it works good in both cases.
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    I can't say what would be causing this issue. The exact same code is executing on all those devices, maybe the problem has something to do with the file you're passing to the AddFile function? On some phones, the file is maybe not existent? You can check logcat to see if it is the case, there will be a "File does not exist at path or permission denied" log.
     
  21. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    8
    Hi Yasir, another question here :

    is there a way, i can share some images that stored internally within my Resources/ folder, if so, which path and how should I access them to share them
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
  23. VastDev

    VastDev

    Joined:
    Oct 19, 2018
    Posts:
    6
    Hi yasirkular,

    thank you so much for the asset. It is really easy to use. I have some question. I am new to Unity and Native fuction, Cuurently I can share the picture but I am still looking for calling share the picture with check-in but no luck. Is it possible to do that with Native Share?

    Thank you in advance for the answer.
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    I couldn't understand what you mean by check-in, can you please explain it a little more?
     
  25. Azgraal

    Azgraal

    Joined:
    Oct 6, 2019
    Posts:
    5
    Hello, I have a question about this plugin. Can it be used to share .mp3 or .wav files from the app (inside StreamingAssets directory, as you mentioned in another post)?

    Thank you.
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Yes but on Android, you have to copy the file to Application.temporaryCachePath via WWW or UnityWebRequest because StreamingAssets files are located inside a jar archive and can't be accessed directly on Android. There should be a sample code in the previous posts.
     
    Azgraal likes this.
  27. Azgraal

    Azgraal

    Joined:
    Oct 6, 2019
    Posts:
    5
    Cheers for the explanation, I'll give it a try.
     
  28. VastDev

    VastDev

    Joined:
    Oct 19, 2018
    Posts:
    6
    The location check-in.
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Oh, I see. I'm not sure if it is possible to share location with NativeShare, you may assume that it is not possible.
     
  30. Azgraal

    Azgraal

    Joined:
    Oct 6, 2019
    Posts:
    5
    I tried using the example code for the screenshot and it works flawlessly with all the social apps I tried.

    However when I try to use the code that was posted here previously for other type of files it doesn't work.

    For starters it logged an error with mLoadPath and mSavePath. Maybe I'm forgetting some step here or programming concept as I'm somewhat of a newbie. Anyway, I tried to declare them as strings and replaced mFile name for "demo.mp3", a file on my resources folder, as a test. Looking at the logcat it saying it "successfuly" created a file with 0 bytes, and of course it is corrupted/empty.

    Can you please tell me what I'm missing?
     
    Last edited: Dec 17, 2019
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Your file needs to reside inside StreamingAssets folder, not in Resources folder.
     
    Azgraal likes this.
  32. Azgraal

    Azgraal

    Joined:
    Oct 6, 2019
    Posts:
    5
    D'oh!
    That was the single thing I was missing. Now it's fully working, even with the modifications I had to do.

    Thank you so much for the help!
     
    yasirkula likes this.
  33. danishsshaikh

    danishsshaikh

    Joined:
    Mar 15, 2019
    Posts:
    5
    Hey, well im new to this.
    But can i share an audio file with this?
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Yes, AddFile function accepts all file extensions.
     
    danishsshaikh likes this.
  35. danishsshaikh

    danishsshaikh

    Joined:
    Mar 15, 2019
    Posts:
    5
    i tried this but this aint working, am i missing something here?
    and im calling this function when the button is clicked from Unity

    Code (CSharp):
    1. public void sendRec()
    2.     {
    3.         string filePath = Application.persistentDataPath;
    4.         string mime = ".wav";
    5.           new NativeShare().AddFile( filePath, mime ).Share();
    6.     }

    Im having this error -

    File does not exist at path or permission denied: C:/Users/Acer/AppData/LocalLow/dan/SpeakUp
    UnityEngine.Debug:LogError(Object)
    NativeShare:AddFile(String, String) (at Assets/Plugins/NativeShare/NativeShare.cs:110)
    RecordAudio:sendRec() (at Assets/Scripts/RecordAudio.cs:65)
    UnityEngine.EventSystems.EventSystem:Update()
     
    Last edited: Dec 20, 2019
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    filePath should point to an existing file however Application.persistentDataPath points to a directory. In addition, NativeShare works on Android and iOS platforms only, so you can't test it on Editor or Standalone build.
     
    danishsshaikh likes this.
  37. danishsshaikh

    danishsshaikh

    Joined:
    Mar 15, 2019
    Posts:
    5
    Sorry i might be troubling you again and again for small stuffs. I tried the above code on Android aswell.
    It isint working.

    But well, here i am storing the audio inside the Unity(windows) using this code

    Code (CSharp):
    1. Path.text = Application.persistentDataPath;
    and my code to share that same audio file was

    Code (CSharp):
    1. public void sendRec()
    2.     {
    3.         string filePath = Application.persistentDataPath;
    4.         string mime = ".wav";
    5.           new NativeShare().AddFile( filePath, mime ).Share();
    6.     }
    also, im having three buttons in my scene (To Record, To stop record, and now this to share that recording) so like if a person records more than 2 times then, how can i point it to like an existing file (also, right now there is one .wav file in Application.PersistentDataPath)

    Can you please guide me little bit here? It would be really awesome. Thank you :)
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    As I said, filePath should point to a file, not a directory; Application.persistentDataPath IS a directory. You can use C#'s
    System.IO.File.Exists(filePath)
    function to see if a file at filePath exists. I'd recommend you to check out the example code here, I think it can clarify things.
     
    danishsshaikh likes this.
  39. TeamWho

    TeamWho

    Joined:
    Jun 22, 2017
    Posts:
    2
    Please help me Master !
    Attribute provider#com.yasirkula.unity.NativeShareContentProvider@authorities value=(com.PhanMinhThanh.Indie_Project_G1.NativeShareContentProvider) from [:NativeShare:] AndroidManifest.xml:6:5-70
     
  40. Atech786

    Atech786

    Joined:
    Nov 25, 2019
    Posts:
    3
    Hello,
    I am trying to share on android Instagram by using this line of code

    Code: new NativeShare().AddFile(Path.Combine(Application.persistentDataPath, FILENAME)).SetTitle("Press Feed button").SetTarget("com.instagram.android", "what class to put here to open directly the feed sharing").Share();

    Currently it is opening the instagram share dialog with the buttons instagram direct, instagram feed and instagram stories. But I just want to show instagram feed button or preferably open the feed share directly any idea how to do that. I know set target has the second argument as android class name but I don't know what class name to put to get the feed share class directly. Any help would be much appreciated. Thanks
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    @TeamWho The _ signs in your bundle identifier might be causing this issue. Can you try replacing your bundle identifier as follows:
    com.PhanMinhThanh.IndieProjectG1


    @Atech786 I've made a quick google search to find that activity's name but didn't find anything. You can check logcat logs while sharing on Instagram feed and see if these logs contain the feed sharing activity's name.
     
  42. Atech786

    Atech786

    Joined:
    Nov 25, 2019
    Posts:
    3
    @yasirkula thanks I am also trying to find it with log cat but no success up till now if any body know please do share here thank you
     
  43. TeamWho

    TeamWho

    Joined:
    Jun 22, 2017
    Posts:
    2
    @yasirkula Thanks you ! i am also trying but no success up .i don't have idea
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Can I see the complete error message? If there are multiple error messages, please post all of them.
     
  45. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    8
    Just want to ask and see if anybody else faces issue like me, I couldn't shared even a plain text on LinkedIn, they work well on Facebook & other apps.
     
  46. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    @yasirkula your plugin is good.. In my project i have used. When i click my share option i have to save my images in gallery. But save to gallery option is not shown in this plugin.

    Is it possible? how can i do it?
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    If you mean adding a "Save to Gallery" option to the list of applications in the share sheet, it is not possible. But you can present two buttons in your own user interface: one for sharing and one for saving to gallery. For the latter, you can use NativeGallery.
     
  48. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    Hi Yasirkula i have used this below code to save the images in gallery. But it is not working. Shall i have to add any permission settings in xml file. if yes where i have to add


    private IEnumerator TakeScreenshotAndSave()
    {
    yield return new WaitForEndOfFrame();

    Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    ss.Apply();

    // Save the screenshot to Gallery/Photos
    Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, "GalleryTest", "Image.png"));

    // To avoid memory leaks
    Destroy(ss);
    }



    i did found any xml file in plugin.......................
     
    Last edited: Jan 11, 2020
  49. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    237
    I have another question also . i have an image i have to take a screen shot for particular area. How can i do it. How can i do it.
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,660
    Coroutines must be called with StartCoroutine (see the example code). If it still doesn't work, see logcat for any error messages. To capture a screenshot of a particular area, please google "unity screenshot partial area".
     
unityunity