Search Unity

Native Share for Android & iOS [Open Source]

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

Thread Status:
Not open for further replies.
  1. unity_tmTrLyCJHohNrw

    unity_tmTrLyCJHohNrw

    Joined:
    Dec 21, 2017
    Posts:
    4
    Hi, why when i use
    new NativeShare().AddFile(screenShotPath).SetSubject("Subject goes here").SetText("Hello world!").Share();
    in Telegram,Twiter i can see text "Hello world!" but in facebook and instagram is empty

    its better plugin,sorry from my english
     
    Last edited: Jul 6, 2018
    gnsx likes this.
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    While sharing content via native share dialog, Facebook only accepts an image or a text, not both. If both are provided, then Facebook omits the text automatically. The only way to share image+text on Facebook is via their Facebook SDK, which this plugin doesn't use. I'm guessing that Instagram also fails for a similar reason.
     
    gnsx likes this.
  3. WasimBashir

    WasimBashir

    Joined:
    Nov 24, 2017
    Posts:
    9
    @yasirkula not woking android 7 and above. i found this exception


    AndroidJavaException: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.wiz.weed.game.editor_sharev5/files/screenshot.jpg exposed beyond app through ClipData.Item.getUri()
    android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.wiz.weed.game.editor_sharev5/files/screenshot.jpg exposed beyond app through ClipData.Item.getUri()
    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1975)
    at android.net.Uri.checkFileUriExposed(Uri.java:2363)
    at android.content.ClipData.prepareToLeaveProcess(ClipData.java:941)
    at android.content.Intent.prepareToLeaveProcess(Intent.java:9944)
    at android.content.Intent.prepareToLeaveProcess(Intent.java:9950)
    at android.content.Intent.prepareToLeaveProcess(Intent.java:9929)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1622)
    at android.app.Activity.startActivityForResult(Activity.java:4751)
    at android.app.Activity.startActivityForResult(Activity.java:4691)
    at android.app.Activity.startActivit
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I didn't expect to see this error here because NativeShare uses a FileProvider to not expose file uris. Can you test your code on another device and try to share on another app to see if this issue is consistent across all devices? Please also make sure that you are using NativeShare and not another sharing solution by mistake (it happened once ^^). It may also be helpful to see a short snippet from your share code.
     
  5. Davidisla

    Davidisla

    Joined:
    Jul 10, 2018
    Posts:
    3
    Hi Yasirkula! Thank you so much for share your plugin! it's amazing ;)

    After add ManifestContainer.aar to my /Plugins/NativeShare/Android directory, my phone start asking me for make Calls permission.

    Is that strictly necessary?
     

    Attached Files:

    gnsx likes this.
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    NativeShare doesn't use any .aar files. You may be using a different share plugin.

    EDIT: Wait, that's the custom aar that I've posted previously. Let me see what can be done.

    EDIT2: You can try adding
    <uses-sdk android:minSdkVersion="4" />
    or
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4" />
    before the <application> tag. However, I'd really suggest you to edit the main AndroidManifest file as suggested in the documentation, rather than using an aar file.
     
    Last edited: Jul 23, 2018
  7. Davidisla

    Davidisla

    Joined:
    Jul 10, 2018
    Posts:
    3
    Thank you for your answer ;)

    If a remove the .arr file, I get an "Can't file ContentProvider, share not possible!" error. Only this file resolved the issue, but maybe I have something wrong in my Manifest.. :|
     

    Attached Files:

  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I don't think you need <meta-data ... /> inside the provider. Other than that, assuming that your manifest is located exactly at Assets/Plugins/Android (and not at e.g. Assets/Plugins/NativeShare/Android) with .xml extension, everything seems OK.
     
  9. Davidisla

    Davidisla

    Joined:
    Jul 10, 2018
    Posts:
    3
    You are totally right!! ;)

    Now the puglin is working perfectly for me, thank you so much!
     
    yasirkula likes this.
  10. kurtiswoww

    kurtiswoww

    Joined:
    Oct 2, 2013
    Posts:
    16
    Hey yasirkula, a few questions:
    1) what is the target for Twitter? I can't seem to figure that out
    2) settarget only works for android yes? is there something similar we can do for ios?

    thanks!
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    1) Seems like Composer activity had different names on different versions. You can try the following code (not tested):

    Code (CSharp):
    1. string androidPackageName, androidClassName;
    2. if( NativeShare.FindTarget( out androidPackageName, out androidClassName, "com.twitter.android", ".*[cC]omposer.*" ) )
    3. {
    4.     // Call NativeShare.SetTarget( androidPackageName, androidClassName ) here
    5. }
    2) Inside NativeShare.mm, you can give a value to activity.excludedActivityTypes to exclude certain applications from the share sheet. In theory, if you exclude everything except Twitter, it should share on Twitter.
     
    Last edited: Mar 6, 2019
  12. duckizz

    duckizz

    Joined:
    Mar 15, 2015
    Posts:
    9
    How do I add the activity.excludedActivityTypes?
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  14. Kmess

    Kmess

    Joined:
    Dec 21, 2013
    Posts:
    11
    Hi Yasirkula,

    Thanks for your work on the plugin, it's been really useful. Recently, I've been seeing the plugin request permissions, specifically READ_PHONE_STATE and WRITE_EXTERNAL_STORAGE.

    Here is the log from the Gradle manifest merger:
    This is with me having the provider defined in the main manifest located in Plugins/Android/AndroidManifest.xml

    I'm wondering if this is due to the plugin not having a default manifest w/ the minsdk version?

    My setup:
    Unity 2017.4.1f1 on OSX
     
    gnsx likes this.
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Do you have any aar files inside Plugins/NativeShare or are you using any of my other plugins in your project? Because adding a <provider> to Plugins/Android/AndroidManifest.xml won't affect the permissions.
     
  16. duckizz

    duckizz

    Joined:
    Mar 15, 2015
    Posts:
    9
    awesome! thanks! it seems that there are still stuff that ios will not allow you to hide.. like the "more..." button.. hmmm
     
    gnsx likes this.
  17. Kmess

    Kmess

    Joined:
    Dec 21, 2013
    Posts:
    11
    @yasirkula - nope, I only have Plugins/NativeShare/Android/NativeShare.jar - this is using the recent update from the asset store. The project has aar plugins but these aren't relating to NativeShare and are in the Plugins/Android folder (Firebase / GPG).

    And yeah that's what I was thinking but the manifest merger specifically points out NativeShare for having a targetsdkVersion less than 4 even though there is no manifest.

    The main Android manifest file has
     <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" />


    and then the provider name is (in the main manifest):
        <provider android:name="com.yasirkula.unity.UnitySSContentProvider" android:authorities="myuniqueidentifier" android:exported="false" android:grantUriPermissions="true" />
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  19. Kmess

    Kmess

    Joined:
    Dec 21, 2013
    Posts:
    11
    Is it possible to include an AAR w/ it's own manifest? I tried to replace the NativeJar.jar with an AAR and the app can't find the java class from the plugin. This probably will solve the issue
     
  20. Kmess

    Kmess

    Joined:
    Dec 21, 2013
    Posts:
    11
    Also for more info from your last post @yasirkula

    I have the following in the main manifest

    <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />


    we also use cloud build for our builds, so having a specific Android build tools version isn't ideal.

    So after this we still see the permissions get added by the manifest merger o_O
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  22. Kmess

    Kmess

    Joined:
    Dec 21, 2013
    Posts:
    11
    Okay - this has been extremely confusing but this issue isn't due to the Share plugin. I was mistaken because the share plugin has the same prefix in the package name as the IngameDebugConsole. We also use this plugin (before you shared the link - also another amazing plugin). So when the manifest merger was giving us the message: reason: com.yasirkula.unity has a targetSdkVersion < 4, that was due to the IngameDebugConsole not the Share had the issue.

    So the permission issue is due to IngameDebugConsole aar not having minsdk/targetsdk defined in the aar. I went ahead and added it and the permissions went away. It's not the sharing plugin's issue, my apologies on that end.
     
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can extract the classes.jar file in it and then delete the aar file. READ_LOGS permission is only necessary to read Logcat logs and I've even read that this permission is not necessary anymore. So the AndroidManifest in the aar is only there as a precaution.
     
  24. endlessfruit

    endlessfruit

    Joined:
    Mar 29, 2018
    Posts:
    1
    Hello yasirkula! Thanks for plagin a lot!
    I use it for iOS app and I need to share screenshot image (already saved to direct album) with preview of my certain album or at least last images of gallery (such as when you try to share from native ios gallery). Is it possible do with your plugin or may be you can give any advice to modify plagin to get I want?
     
  25. IndieGeek

    IndieGeek

    Joined:
    Sep 30, 2016
    Posts:
    16
    Hi, how can I share only for Instagram or for Facebook? I only want android prompt shown for app individually!
    I already gave 'appPackage' Id in 'ShareAndroid' function but then no prompt window of the android popup.
    Id I gave for facebook was "com.facebook.katana" but no luck so far!
     
  26. femoreti

    femoreti

    Joined:
    May 9, 2014
    Posts:
    4
    I've tried to share on facebook with text only and Facebook omits the text. Is it only with me or facebook don't accept native share to auto fill the text?
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @endlessfruit You can pick an image from Photos using NativeGallery, but it doesn't support showing only the specified album. I'm not sure whether or not what you are asking is possible at the moment.

    @IndieGeek Firstly, please make sure that you are using my NativeShare plugin because it doesn't have a ShareAndroid function. If it was a typo, you can try using the NativeShare.FindTarget function to find the installed Facebook app's package name. See the documentation for more info: https://github.com/yasirkula/UnityNativeShare/#utility-functions

    @femoreti AFAIK, it is possible to share text only on Facebook (at least on Android). Can you try it on another device?
     
    IndieGeek likes this.
  28. rajat_neo

    rajat_neo

    Joined:
    Nov 30, 2017
    Posts:
    2
    I am trying this code
    var path = Application.persistentDataPath + "/" + GALLERY_PATH + "/" + fileName;
    new NativeShare().SetSubject("Replay").SetTitle("Sharing").SetText("Replay").AddFile(path).Share();

    my native share panel opens but can only able to send text (Replay) don't know why not able to add file (Which is video file) Please help
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Does File.Exists(path) return true? Your path should point to an existing file.
     
  30. chiragms

    chiragms

    Joined:
    Mar 16, 2018
    Posts:
    2
    It works perfectly but its only working for "Build Settings > Build System > Internal" builds but it doesnt work for "Build Settings > Build System > Gradle" builds.
    I'm using Gradle to enable ProGuard.
    Please help...
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Try adding the following line to ProGuard filters:
    -keep class com.yasirkula.unity.* { *; }
     
    Tenebris_Lab likes this.
  32. FriedCandle

    FriedCandle

    Joined:
    Mar 4, 2015
    Posts:
    3
    It works perfectly for me on iOS, but when I test it on the Android version of my app, the content provider does not show up.. I think I setup the AndroidManifest correctly but I included it. Is there something I need to add in the New NativeShare object?
     

    Attached Files:

  33. Shumail

    Shumail

    Joined:
    Jun 8, 2018
    Posts:
    1
    I am using your assets and simple text and links are working totally fine but when I am sharing image using native share dialog it says "can't find content provider, share is not possible"

    This is code I am using to take screenshot and share
    please help me with this

    Code (CSharp):
    1. private IEnumerator TakeSSAndShare ()
    2.     {
    3.         yield return new WaitForEndOfFrame ();
    4.  
    5.         Texture2D ss = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
    6.         ss.ReadPixels (new Rect (0, 0, Screen.width, Screen.height), 0, 0);
    7.         ss.Apply ();
    8.  
    9.         string filePath = Path.Combine (Application.temporaryCachePath, "shared img.png");
    10.         print ("File path is Asad: " + filePath);
    11.         File.WriteAllBytes (filePath, ss.EncodeToPNG ());
    12.  
    13.         // To avoid memory leaks
    14.         Destroy (ss);
    15.  
    16.         new NativeShare ().AddFile (filePath).SetSubject ("Subject goes here").SetText ("Hello world!").Share ();
    17.  
    18.         // Share on WhatsApp only, if installed (Android only)
    19.         if (NativeShare.TargetExists ("com.whatsapp"))
    20.             new NativeShare ().AddFile (filePath).SetText ("Hello world!").SetTarget ("com.whatsapp").Share ();
    21.     }
    My manifest is attached below
     

    Attached Files:

  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @FriedCandle @Shumail make sure that AndroidManifest is located exactly at Assets/Plugins/Android/AndroidManifest.xml, i.e. it should have xml extension and it should be located inside Plugins/Android and not Plugins/NativeShare/Android. Also make sure that
    <provider ... />
    is inside
    <application>...</application>
    , not
    <activity>...</activity>
    .
     
  35. tjPark

    tjPark

    Joined:
    Mar 19, 2015
    Posts:
    13
    I am not sure but when I tried to use yasikula's Native Camera + Native Gallery at the same time, this exception occurred.
    after removing native camera(and adjusted android manifest), I could use native gallery without error.
     
  36. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    I have used your plugin. It is superb... I have shared my image in fb, twitter. when i post my image in skype.only text message is displaying. Not my image is sharing... What i have to do...

    Another Doublt.. I have paint option. and i want record how they users are painting. Did this plugin helps to record. and to share....

    is there any want to convert into gif and upload to fb, or skype or anything...
     
  37. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    My Image is sharing in fb and twitter. But Skype my image is not posted... Only text message is displaying. What i have to do...
     
  38. chandu1994

    chandu1994

    Joined:
    May 24, 2018
    Posts:
    2
    Not working in my case give some error like :

    `NativeShare' does not contain a definition for `AddFile' and no extension method `AddFile' of type `NativeShare' could be found. Are you missing an assembly reference?
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @tjPark If you use NativeShare+NativeCamera together, you need to have at least two
    <provider ... />
    s in your AndroidManifest (one for each plugin). Maybe you replaced one with the other?

    @Alexander21 Some apps (like Facebook and apparently Skype) may not support image+text combination. NativeShare doesn't have any app-specific logic, so if an app doesn't support image+text sharing, it is not possible to alter that behaviour :/ For consistency, you may prefer to share only text or only image.

    @chandu1994 Are there any other NativeShare classes in your project? If so, try renaming mine to NativeShare2 and use NativeShare2 in your code.
     
  40. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    @yasirkula Thanks For Your Reply... Yas i have removed the text and i have shared the image in Skype. It is sharing the image. But Another one thing

    When i share the image in fb.. it takes time. When i post the image. The black screen is displaying.round symbol comes to start to end point . after it says the image is posted..

    but twitter is posting immediately.. Skype it says the uploading time that is (20 % to 100% ) and it send to receipent.

    Fb is displaying black screen after it says posted. What is the reason . How can i avoid it...
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I honestly don't know. NativeShare just creates an Intent and the Intent launches the Facebook activity. There is no intentional black screen in the process.
     
  42. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    @ yasirkula Actually When i click the share button the image is posting in facebook. After i click post button.A black screen is displaying and file upload and it says

    connection is taking longer than normal to upload facebook and it says posted........

    is there any solution.. or anything wrong in my side...
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I don't think there is anything wrong on your side. You can try the app on another device to see if the issue is persistent there. But regardless, I don't know any solutions for this behaviour.
     
  44. jpazucena

    jpazucena

    Joined:
    Aug 1, 2018
    Posts:
    2
    @ysirkula

    I've tried out your plugin and it was really easy to integrate and use. One thing that I noticed is that for Android 7.1 devices that I tested with, the chooser popup that shows all the apps that can handle the share intent doesn't show in fullscreen. The status and navigation bars show up and the navigation bar obscures the bottom of the chooser popup (which also obscures any apps displayed on that row). Do you have any thoughts on how I might go about correcting this issue? Either hiding the status/navigation bars or moving the popup so that nothing is obscured. Thanks in advance.
     
    Last edited: Sep 20, 2018
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    That's interesting. Does the navigation bar not become invisible after a few seconds? Is the status bar also visible while navigation bar is visible? Is it possible that the navigation bar appears due to a finger swipe near the bottom of the screen? Can I see a screenshot?
     
  46. jpazucena

    jpazucena

    Joined:
    Aug 1, 2018
    Posts:
    2
    No. The navigation bar remains until I dismiss the chooser popup.

    Yes. The status bar and soft navigation bar are made visible when the chooser popup is displayed.

    No. I've been careful to avoid touching the screen after triggering the chooser popup to display.

    Attached.
     

    Attached Files:

    yasirkula likes this.
  47. Meepo0

    Meepo0

    Joined:
    Nov 24, 2017
    Posts:
    31
    Hii i am a little new to this so can you pls help me, i want to share the screenshot of my game with a link to go to download the game (link depends on ios or android) and a text saying the highscore
    Thank you for the answer in advance :)
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  49. Meepo0

    Meepo0

    Joined:
    Nov 24, 2017
    Posts:
    31
    @yasirkula Hey Thanks for the help but after putting the code it shows the error on the line :

    new NativeShare().AddFile(filePath).SetSubject("Subject goes here").SetText("Hello world!").Share();

    says that namespace NativeShare could not be found i also added the using NatShareU; on top but still show the error

    thanks for help :)
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
Thread Status:
Not open for further replies.