Search Unity

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,184
  2. Emanuele_portalDude

    Emanuele_portalDude

    Joined:
    Jan 9, 2017
    Posts:
    4
    This is what logcat tells me. The AndroidManifest.xml is under Assets/Plugins/Android

    EDIT: ok I found the problem: I just needed to rename the android:authorities with a different string (I used the same string inside the NativeCamera snippet, my bad!)
     

    Attached Files:

    Last edited: Dec 6, 2018
    yasirkula likes this.
  3. julietagur

    julietagur

    Joined:
    Nov 7, 2017
    Posts:
    3
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Its
    <application>...</application>
    tag should look like this:

    Code (CSharp):
    1. <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@style/UnityThemeSelector" android:debuggable="false" android:isGame="true">
    2. <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density">
    3.   <intent-filter>
    4.     <action android:name="android.intent.action.MAIN" />
    5.     <category android:name="android.intent.category.LAUNCHER" />
    6.   </intent-filter>
    7.   <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    8. </activity>
    9. <!-- To support the ODG R7 in stereo mode we must add the following library. -->
    10. <uses-library android:name="com.osterhoutgroup.api.ext" android:required="false" />
    11. <meta-data android:name="unity.build-id" android:value="63f7ad46-9d23-4df7-8e2a-17df67641cea" />
    12. <meta-data android:name="unity.splash-mode" android:value="0" />
    13. <meta-data android:name="unity.splash-enable" android:value="True" />
    14. <meta-data android:name="android.max_aspect" android:value="2.1" />
    15. <provider
    16.   android:name="com.yasirkula.unity.UnitySSContentProvider"
    17.   android:authorities="JULIETAGUR"
    18.   android:exported="false"
    19.   android:grantUriPermissions="true" />
    20. </application>
    21.  
    It's the first time I hear that any changes to Assets/Plugins/Android/AndroidManifest.xml not apply to the build, I don't really know why this issue is occurring :/
     
  5. danidiazr

    danidiazr

    Joined:
    Dec 27, 2016
    Posts:
    7
    Hey!

    I just bought your asset... and I have a problem

    When I use NativeShare.ShareTexture(Texture2D), nothing happens. I had some problems with the Manifest cause I'm using another plugin for AR with it's own AndroidManifest, maybe the problem it's that I merged badly the manifests, but I don't know what else can be my problem. Any idea? Thanks!
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
  7. Deftboxsolutions

    Deftboxsolutions

    Joined:
    Sep 6, 2018
    Posts:
    2
    Share does not work on IOS.

    I mean Text is sharing but when I share screenshot it just share title and text not image.
     
  8. KhaledDebuch

    KhaledDebuch

    Joined:
    Dec 8, 2018
    Posts:
    3
    Hi,
    Can I show only instagram and facebook in list of Native Share for iOS ?
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    @Deftboxsolutions Some applications may not support sharing an image with a text. I'd recommend you to remove the text from the shared content for maximum compatibility, if possible.

    @KhaledDebuch You may try inserting something like the following to here:

    Code (CSharp):
    1. activity.excludedActivityTypes = @[
    2.     UIActivityTypeAssignToContact,
    3.     UIActivityTypePrint,
    4.     UIActivityTypeAddToReadingList,
    5.     UIActivityTypeSaveToCameraRoll,
    6.     UIActivityTypeOpenInIBooks,
    7.     @"com.apple.mobilenotes.SharingExtension",
    8.     @"com.apple.reminders.RemindersEditorExtension"
    9. ];
    Credit: https://stackoverflow.com/a/39710905/2373034
    Also see: https://developer.apple.com/documentation/uikit/uiactivitytype?language=objc
     
    kd_unity and KhaledDebuch like this.
  10. kk3hi3123

    kk3hi3123

    Joined:
    Aug 17, 2016
    Posts:
    12
    Hello. I am using your plugin to share the captured screenshot and test it in my Android device.

    I firstly save the image into Application.dataPath/filename. It comes out a share box but when I try to send a gmail, only text and title is shared.

    Then I copy the sample code from GitHub and build again. This time the share box does not come out. And also no error or warning message comes out.

    Here is my code:

    Code (CSharp):
    1. public void takeScreenShot(){
    2.         myCamera.targetTexture = RenderTexture.GetTemporary(Screen.width, Screen.height, 16);
    3.         takeScreenshotOnNextFrame = true;
    4.     }
    5.  
    6. private void OnPostRender()
    7.     {
    8.         if (takeScreenshotOnNextFrame){
    9.             takeScreenshotOnNextFrame = false;
    10.             RenderTexture renderTexture = myCamera.targetTexture;
    11.  
    12.             Texture2D result = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
    13.             Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height);
    14.             result.ReadPixels(rect, 0, 0);
    15.  
    16.             byte[] byteArray = result.EncodeToPNG();
    17.             filePath = Application.temporaryCachePath + "/ScreenShot.png";
    18.             System.IO.File.WriteAllBytes(filePath, byteArray);
    19.  
    20.             Debug.Log("ScreenShot saved to: " + filePath);
    21.  
    22.             RenderTexture.ReleaseTemporary(renderTexture);
    23.             Destroy(result);
    24.             myCamera.targetTexture = null;
    25.         }
    26.     }
    27.  
    28. public void shareScreenShot(){
    29.         new NativeShare().AddFile(filePath).SetSubject("My Result!")
    30.                          .SetText("I have finished Level " + GameManager.Instance.levelManager.CurrentLevelNum + "!").Share();
    31.         Debug.Log("Share Image: " + filePath);
    32.     }
     
  11. KhaledDebuch

    KhaledDebuch

    Joined:
    Dec 8, 2018
    Posts:
    3
    Thank you very much, It works properly.
     
  12. Deftboxsolutions

    Deftboxsolutions

    Joined:
    Sep 6, 2018
    Posts:
    2

    Hello @yasirkula ,
    thanks for replying I want to share game link along with screenshot,
    is it possible to do in IOS??
    When I remove text part from nativeshare I'm able to share SS but when I add text part it share text only.
     
    Last edited: Dec 19, 2018
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    @kk3hi3123 The sample code on GitHub must be attached to a GameObject as component and you must click the screen to trigger the share. Did nothing happen even though you followed these steps? For the error messages, did you check Logcat or Unity's Console? If it is the latter, try using logcat, as well.

    @Deftboxsolutions I haven't found a way to accomplish this yet. NativeShare uses UIActivityViewController to share the media, and it is up to the shared application handle the shared content properly.
     
  14. kk3hi3123

    kk3hi3123

    Joined:
    Aug 17, 2016
    Posts:
    12
    I can see my Debug.Log message. But no error message comes out.
     
  15. BoatBest

    BoatBest

    Joined:
    Jan 4, 2016
    Posts:
    82
    Hello Sir!
    I would like to know if there is any purpose of using this line of code when taking screen shot?
    And also why sometime when I remove this line it could share and couldn't share because file isn't exist.
    File.WriteAllBytes(_filePath, ss.EncodeToPNG());
     
    Last edited: Dec 20, 2018
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    @kk3hi3123 I really want to help but there is just not enough information to figure out the cause of this issue. I don't think I can help you with this problem :/

    @BoatBest NativeShare's AddFile function requires you to enter the path of an existing file. File.WriteAllBytes helps us create an image file from a texture.
     
    BoatBest likes this.
  17. khean

    khean

    Joined:
    Jun 16, 2018
    Posts:
    2
    Hello @yasirkula, I unable to build on ios platform after I created an assembly file in native share plugin to be referred by my script folder assembly. Related error was
    Assets/Plugins/NativeShare/Editor/NSPostProcessBuild.cs(5,19): error CS0234: The type or namespace name `iOS' does not exist in the namespace `UnityEditor'. Are you missing an assembly reference?

    Seem like the assembly in native share is missing the ios namespace in editor folder.
    Do you have any idea for this?
     
    Last edited: Dec 22, 2018
  18. khean

    khean

    Joined:
    Jun 16, 2018
    Posts:
    2
    Thanks, i found the answer. If any of u guys curious about it,
    https://forum.unity.com/threads/the...f-and-using-the-unityeditor-ios-xcode.524432/
     
    yasirkula likes this.
  19. kd_unity

    kd_unity

    Joined:
    Dec 19, 2018
    Posts:
    5
    Hi Yasirkula,
    Thank you very much on your asset "Native Share for Android & iOS".

    Can I show only instagram and facebook in list of Native Share for Android ?
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    At the moment, it is not possible, sorry.
     
  21. kenfalco

    kenfalco

    Joined:
    Jul 18, 2012
    Posts:
    15
    Hello,thankyou for the nice plugin!
    I 'm trying to upload a photo (png 140x140) but it does not work. Some idea?
    I'm on IOS.

    The file is inside Assets/StreamingAssets

    string sFile = Application.dataPath + "/Raw"+ "/"+"logo.png";
    s.AddFile(sFile);

    P.S the file is found. i'm sharing with whatsapp

    Gabriel
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Are you sharing with a text? Does sharing without a text work?
     
  23. kenfalco

    kenfalco

    Joined:
    Jul 18, 2012
    Posts:
    15
    Hello,with SetText SetTitle SetSubject.
    I want create a share like the app Clash Royale in whatsapp.

    upload_2019-1-25_8-25-53.png
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
  25. kenfalco

    kenfalco

    Joined:
    Jul 18, 2012
    Posts:
    15
    Thank you! :)
     
  26. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    @yasirkula Do you know if there's a way to check on iOS first if they have an app before trying to share? So to check if the app has Facebook or Instagram? Then only share to those.
     
  27. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    Also, it seems like when I try to share on iOS in any of the apps, it opens the general iOS share popup, and when I select an app, it only posts text, not the picture despite using AddFile.

    Edit:
    It looks like I'm hitting this line:
    Debug.LogError( "File does not exist at path or permission denied: " + filePath );

    Even though earlier the path seems to be generated.
     
    Last edited: Jan 28, 2019
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    To check whether or not those apps exist, you can try adding the following functions to NativeShare.mm:

    Code (CSharp):
    1. extern "C" int _NativeShare_IsFBAvailable() {
    2.     if( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]] )
    3.         return 1;
    4.  
    5.     return 0;
    6. }
    7.  
    8. extern "C" int _NativeShare_IsInstagramAvailable() {
    9.     if( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"instagram://app"]] )
    10.         return 1;
    11.  
    12.     return 0;
    13. }
    And the following to inside the NativeShare class:

    Code (CSharp):
    1. #if !UNITY_EDITOR && UNITY_IOS
    2. [System.Runtime.InteropServices.DllImport( "__Internal" )]
    3. private static extern int _NativeShare_IsFBAvailable();
    4.  
    5. [System.Runtime.InteropServices.DllImport( "__Internal" )]
    6. private static extern int _NativeShare_IsInstagramAvailable();
    7. #endif
    8.  
    9. public static bool IsFBAvailable()
    10. {
    11. #if !UNITY_EDITOR && UNITY_IOS
    12.     return _NativeShare_IsFBAvailable() == 1;
    13. #else
    14.     return false;
    15. #endif
    16. }
    17.  
    18. public static bool IsInstagramAvailable()
    19. {
    20. #if !UNITY_EDITOR && UNITY_IOS
    21.     return _NativeShare_IsInstagramAvailable() == 1;
    22. #else
    23.     return false;
    24. #endif
    25. }
    Note that these functions will work on iOS only (not tested). To test sharing to specific apps only, see: https://forum.unity.com/threads/native-share-for-android-ios-open-source.519865/page-4#post-4011874

    Does File.Exists(filePath) return true?
     
  29. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    @yasirkula All I care about is iOS functionality right now, as everything works perfectly in Android builds.

    It looks like when I implemented the canOpenURL code, I get this error in xCode at runtime:
    -canOpenURL: failed for URL: "fb://" - error: "This app is not allowed to query for scheme fb"
     
    Last edited: Jan 29, 2019
  30. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    Also, Does File.Exists(filePath) is returning false. I wonder why that would be?

    The path I save to is Application.persistentDataPath. I use the NativeGallery plugin you have.

    This is an example path where I'm saving:
    /var/mobile/Containers/Data/Application/F71FBE76-7F82-4DBD-8E59-959807DDED7E/Documents/Selfie20190128184806.jpg
     
    Last edited: Jan 29, 2019
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Ben-BearFish likes this.
  32. CB-Mishra

    CB-Mishra

    Joined:
    Feb 17, 2018
    Posts:
    4
    Hi, Yasirkula,
    If I using on android
    new NativeShare().AddFile(filePath).SetSubject("Subject goes here").SetText("Hello world!").Share();
    is not prompted for share the image.


    And If I using on android
    new NativeShare().SetSubject("Subject goes here").SetText("Hello world!").Share();

    is prompted for share.

    I am attaching the AndoidManifest.XML file after build from Temp\StagingArea.

    I think this is problem of Mime type.
     

    Attached Files:

  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
  34. JamesWebfibre

    JamesWebfibre

    Joined:
    Feb 13, 2019
    Posts:
    1
    Hi, yasirkula.

    Your plugin is fantastic and works as expected on Android 7 (not tested on Android 8 yet). Would it be possibly from the functions you've written to open a file in it's default reader rather than share?

    Thanks,

    James.
     
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Hi, opening a file would require an ACTION_VIEW intent but my plugin doesn't use it. So, unfortunately, NativeShare won't work for you.

    Best regards.
     
  36. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    220
    @yasikula.. I have download your plugin. It is Superb.Sharing is working fine. Actually i have to share my app link to my friends.

    When the user clicks the links .it should go to playstore or itunes. and the user should install my app.

    In that i have to know which user clicked my link. and then i have to give rewards to the user who installed my app...

    How can i do it?
     
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    I don't know how AAA titles achieve that but you can share a link that leads to your own website and contains a unique identifier for the user sharing the link (e.g. https://mygamewebsite.com/Share?id=12A85F23C). You can then use that ID to reward the user and redirect the user to the app store page. To see whether or not an app is installed, this might help: https://answers.unity.com/questions/1331116/how-to-reward-the-player-after-they-install-anothe.html

    Please let me know if you find a polished solution for this task.
     
    Last edited: Feb 16, 2019
  38. pedro_eloideias

    pedro_eloideias

    Joined:
    Feb 18, 2019
    Posts:
    7
    I'm making a AR app, and I have a button that I want to take a SS and share, I tried using your sample code on github, with no sucess. I tried using only the function to share a text, and it worked. In the app folders I can find the SS, but when I use the full line of code, nothing happens.
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Did you update your AndroidManifest (on Android)? Are there any error messages on logcat/Xcode console?
     
  40. pedro_eloideias

    pedro_eloideias

    Joined:
    Feb 18, 2019
    Posts:
    7
    02-19 14:28:59.302 1112 7675 I chatty : uid=1006(camera) CAM_isp_trigger identical 2 lines
    02-19 14:28:59.303 1112 7675 E mm-camera: <ISP ><ERROR> 499: sce_found_boundaries: sce_found_boundaries: Error: less than two intersections 0
    02-19 14:29:00.029 6052 8547 D EventNotificationJob: Running EventNotificationJob, isDetail=true
    02-19 14:29:00.034 6052 8547 D EventNotificationJob: finished processing events.
    02-19 14:29:00.897 6052 6366 D ClClient: Not sending keepalive. Current connection state=STOPPED
    02-19 14:29:02.126 897 897 I SFPerfTracer: trigger: frame rate (-49.874%) (30.076 fps) (33.249 ms) (212 drops) (286 frames)
    02-19 14:29:02.127 897 897 I SFPerfTracer: triggers: (rate: 3857:2058461) (compose: 0:277) (post: 0:1416) (render: 4:1504) (286:8494930 frames) (287:9302243)
    02-19 14:29:02.127 897 897 D SFPerfTracer: layers: (1:8) (StatusBar#0 (0xac8d4000): 3:616713)* (com.android.systemui.ImageWallpaper#0 (0xaeae0000): 0:22181)* (animation background stackId=1#0 (0xac7f9000): 0:4186)* (Sprite#0 (0xac71f000): 0:1503)* (DimLayerController/Stack=0#0 (0xac73f000): 0:15605)* (animation background stackId=0#0 (0xaca2b000): 0:2)* (NavigationBar#0 (0xac1d6000): 0:34627)* (com.Eureka.Ra/com.unity3d.player.UnityPlayerActivity#0 (0xac163000): 0:27)*
    02-19 14:29:02.912 7387 7403 E Unity : Can't find ContentProvider, share not possible!


    That's what is showing on logcat


    And yes, I change the XML and added the provider tag.

    The changes that I made on the XML, doesn't seem to be saved, once I build the project, I checked on the folder Temp.
     
    Last edited: Feb 19, 2019
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Did you add the provider tag to AndroidManifest as stated in README?
     
  42. pedro_eloideias

    pedro_eloideias

    Joined:
    Feb 18, 2019
    Posts:
    7
    No more problems, it's was an issue with my phone, took some time to figure it out, but now it works perfectly.
     
    Last edited: Feb 19, 2019
    yasirkula likes this.
  43. kamihiro74

    kamihiro74

    Joined:
    May 15, 2013
    Posts:
    13
    Hi, Thank you for such great asset!
    I'm working with the iOS and share the video files through Airdrops.
    and it works really well.
    However, I'm having a problem to using Airdrop to share multiple video files with iOS.

    I call the natshare in the loop
    something like this
    foreach (string videoPath in videoPathList) {
    string[] splitPath = videoPath.Split (':');
    string filePath = splitPath[0];
    Debug.Log("FILE::::" + filePath + "=====" + videoPath);
    new NativeShare().AddFile("file://"+filePath).SetSubject("Portal").Share();
    }
    it just doesn't work at all. it will just show up dialog but has "Other" button on it.
    here the screen capture
    IMG_F31C067097FC-1.JPEG

    I'm using other Unity Asset to get the path in the gallery
    https://assetstore.unity.com/packages/tools/integration/mobile-media-picker-complete-template-122031

    please let me know if there is a way to share the multiple video files.

    Thanks
     
    Last edited: Feb 20, 2019
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    You have to call the AddFile method of the same NativeShare object:

    Code (CSharp):
    1. NativeShare nativeShare = new NativeShare();
    2. foreach (string videoPath in videoPathList)
    3. {
    4.     string[] splitPath = videoPath.Split (':');
    5.     string filePath = splitPath[0];
    6.     Debug.Log("FILE::::" + filePath + "=====" + videoPath);
    7.     nativeShare.AddFile(filePath);
    8. }
    9. nativeShare.SetSubject("OnwardPortal").Share();
    If it doesn't work, check if Debug.Log(System.IO.File.Exists(filePath)) logs 'True' to the console and check logcat/Xcode console for any meaningful error messages.
     
  45. kamihiro74

    kamihiro74

    Joined:
    May 15, 2013
    Posts:
    13

    Thank you, it works, it show the share dialog, but I couldn't send through airdrop
    but later I figured it out, I need to use files from other directory something like temporaryCachePath instead of using gallery path.
     
    yasirkula likes this.
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    Thanks for sharing your workaround, I didn't know about this issue so I think this workaround will be useful in the future.
     
  47. rsherzod

    rsherzod

    Joined:
    Oct 30, 2016
    Posts:
    5
    Hi Yasirkula, Could you please explain what exactly do you mean by
    - change the value of PHOTO_LIBRARY_USAGE_DESCRIPTION in Plugins/NativeShare/Editor/NSPostProcessBuild.cs

    I found the script, but when change the value what should I replace it with, please can you provide some example thank you.
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    On iOS, when sharing an image or video, share dialog contains an option to save the shared image/video to Photos. When this option is selected, a permission dialog is shown to the user to be able to add the image/video to the Photos. PHOTO_LIBRARY_USAGE_DESCRIPTION is the text shown to the user in the permission dialog that explains why the app is trying to access the Photos.
     
  49. semyou83

    semyou83

    Joined:
    Jan 30, 2018
    Posts:
    2
    Hi Yasirkula,
    First of all thank you for sharing your asset. I tried the asset with a simple project : just a "share" button in a canvas. Sharing text with the asset in android worked just fine. However, image sharing crushed the game with the message "Unfortunately, Android System has stopped". I used my Samsung S7 for the test (android version 6.0.1). I tested again the image sharing with my old Samsung S3 (android version 4.1.2) and it worked fine. isn't the asset compatible with all android versions? By the way, I'm using Unity 2017.2.0f3.
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,184
    It should be compatible with all Android versions, this is the first such crash I hear. Does the example code on the GitHub repository also not work? Does the code work on another Unity version, perhaps?