GithubHelp home page GithubHelp logo

nicholassheehan / unity-native-sharing Goto Github PK

View Code? Open in Web Editor NEW
444.0 45.0 120.0 595 KB

A Unity plugin to open native sharing dialogs on iOS and Android, primarily for text and files

License: MIT License

C# 49.22% Objective-C 2.24% Java 36.11% Objective-C++ 12.43%
unity android unity-plugin sharing-screenshots ios

unity-native-sharing's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-native-sharing's Issues

Sharing success confirmation

Hi,
This plugins is very useful and working perfectly fine.
I have one question, is there any way i can find whether user has actually shared the post or just came back by click share popup.

Thanks for your help in advance.

Fix for "unable to process the file" sending plain text to Facebook Messenger

Sending just text to Facebook Messenger doesn't work, Messenger says it cant recognize the file. The fix is simple, don't send an empty array to the ShareMultiple function, send an actual null value. The ShareMultiple function is incorrectly looking for a null array, but since the array isn't null it is still attaching an empty EXTRA_STREAM. This is for Android.

In the ShareAndroid function, add a simple null check to the filePath conditional.

else if (filePaths != null) becomes:

else if (filePaths != null && filePaths.Length > 0 && !string.IsNullOrEmpty(filePaths[0]))

Sharing on Messenger don't work

Hey ! First of all, thank you so much for your code, it's simple, clear and do what I exactly needed !

I've just encounter a bug, which is when you want to share an image (PNG file) with Messenger. Everytime I try, I get a popup message saing "Sorry, Messenger was unable to process the file".

Just to let you know, it works perfectly fine on Facebook, Snapchat, WhatsApp, Inbox (Gmail), and a lot more.

I'm using an Android 7.1 and an Android 4.4 for testing.

Ability to share Base64 image

Hello,

To avoid unwanted screenshots on the disk, i've add a small code that allow users to share Base64 image, without the need to save them on disk.
PR : #8

thanks

Image issue

No image is added when sharing on WhatsApp.
No text is added when sharing on Facebook.
iOS 10.2.1

Crash When Sharing,

Every time I share a screenshot on IOS it crashes. This is the crash log.

018-01-07 04:40:24.445 Mzito[6106:1067828] Uncaught exception: NSInvalidArgumentException: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
(
	0   CoreFoundation                      0x25143933 <redacted> + 150
	1   libobjc.A.dylib                     0x248dee17 objc_exception_throw + 38
	2   CoreFoundation                      0x25058d5f <redacted> + 622
	3   Mzito                               0x007d585d -[iOSNativeShare initWithText:withFilePaths:withSubject:] + 870
	4   Mzito                               0x007d54ed +[iOSNativeShare withText:withFilePaths:withSubject:] + 62
	5   Mzito                               0x007d5e3d showSocialSharing + 48
	6   Mzito                               0x000a18ef NativeShare_showSocialSharing_m407316830 + 38
	7   Mzito                               0x000a182b NativeShare_ShareIOS_m2364977555 + 262
	8   Mzito                               0x000a1705 NativeShare_Share_m424583087 + 134
	9   Mzito                               0x000ec115 U3CdelayedShareU3Ec__Iterator0_MoveNext_m961221407 + 310
	10  Mzito                               0x006c1cb9 SetupCoroutine_InvokeMoveNext_m2975616245 + 112
	11  Mzito                               0x007a2113 _Z53RuntimeInvoker_Void_t1841601450_Il2CppObject_IntPtr_tPK10MethodInfoPvPS2_ + 24
	12  Mzito                               0x0123b815 _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 116
	13  Mzito                               0x00c731b3 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 62
	14  Mzito                               0x00c6d463 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 44
	15  Mzito                               0x00b86805 _ZN9Coroutine14InvokeMoveNextEP21ScriptingExceptionPtr + 118
	16  Mzito                               0x00b865b3 _ZN9Coroutine3RunEPb + 32
	17  Mzito                               0x00a870f9 _ZN18DelayedCallManager6UpdateEi + 470
	18  Mzito                               0x00b73235 _Z10PlayerLoopv + 956
	19  Mzito                               0x00db9437 _ZL19UnityPlayerLoopImplb + 22
	20  Mzito                               0x0008374b UnityRepaint + 218
	21  Mzito                               0x00083605 -[UnityAppController(Rendering) repaintDisplayLink] + 76
	22  libMTLInterpose.dylib               0x03a08865 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 276
	23  QuartzCore                          0x2779fa0b <redacted> + 106
	24  QuartzCore                          0x2779f857 <redacted> + 594
	25  IOMobileFramebuffer                 0x26e8650b <redacted> + 86
	26  IOKit                               0x25394759 IODispatchCalloutFromCFMessage + 256
	27  CoreFoundation                      0x250f237d <redacted> + 132
	28  CoreFoundation                      0x251065b3 <redacted> + 34
	29  CoreFoundation                      0x25105cc7 <redacted> + 342
	30  CoreFoundation                      0x251040d9 <redacted> + 1688
	31  CoreFoundation                      0x25053229 CFRunLoopRunSpecific + 520
	32  CoreFoundation                      0x25053015 CFRunLoopRunInMode + 108
	33  GraphicsServices                    0x26643ac9 GSEventRunModal + 160
	34  UIKit                               0x29727189 UIApplicationMain + 144
	35  Mzito                               0x0007b7b7 main + 214
	36  libdyld.dylib                       0x24cfb873 <redacted> + 2
)
2018-01-07 04:40:24.448 Mzito[6106:1067828] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x2514391b 0x248dee17 0x25058d5f 0x7d585d 0x7d54ed 0x7d5e3d 0xa18ef 0xa182b 0xa1705 0xec115 0x6c1cb9 0x7a2113 0x123b815 0xc731b3 0xc6d463 0xb86805 0xb865b3 0xa870f9 0xb73235 0xdb9437 0x8374b 0x83605 0x3a08865 0x2779fa0b 0x2779f857 0x26e8650b 0x25394759 0x250f237d 0x251065b3 0x25105cc7 0x251040d9 0x25053229 0x25053015 0x26643ac9 0x29727189 0x7b7b7 0x24cfb873)
libc++abi.dylib: terminating with uncaught exception of type NSException

Mzito is the name of my app.
After adding an exception breakpoint the crash seems to be coming from line 91 in iOSNativeShare.m

			`NSArray *paths = [mfilePath componentsSeparatedByString:@";"];
	int i;
	for (i = 0; i < [paths count]; i++) {
		NSString *path = [paths objectAtIndex:i];
		
		if([path hasPrefix:@"http"])
		{
			NSURL *url = [NSURL URLWithString:path];
			NSError *error = nil;
			NSData *dataImage = [NSData dataWithContentsOfURL:url options:0 error:&error];
			
			if (!error) {
				UIImage *imageFromUrl = [UIImage imageWithData:dataImage];
				**[items addObject:imageFromUrl];**
			} else {
				[items addObject:url];
			}
		}`

[items addObject:imageFromUrl];
Am a bit new to developing on IOS but what I understood was the title and path were nil which then threw this exception. Does anyone have a fix for this?

Android 8 sharing issue

I see this error while sharing on Android 8 devices.

E Unity : AndroidJavaException: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.test.company/files/test.png exposed beyond app through ClipData.Item.getUri() E Unity : at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958) E Unity : at android.net.Uri.checkFileUriExposed(Uri.java:2348) E Unity : at android.content.ClipData.prepareToLeaveProcess(ClipData.java:942) E Unity : at android.content.Intent.prepareToLeaveProcess(Intent.java:9753) E Unity : at android.content.Intent.prepareToLeaveProcess(Intent.java:9759) E Unity : at android.content.Intent.prepareToLeaveProcess(Intent.java:9738) E Unity : at android.app.Instrumentation.execStartActivity(Instrumentation.java:1609) E Unity : at android.app.Activity.startActivityForResult(Activity.java:4472) E Unity : at android.app.Activity.startActivityForResult(Activity.java:4430) Unity : at android.app.Activity.startActivity(Activity.java:4791

README.md suggested git string doesn't work for Package Manager

Trying to grab the package in unity 2019.3.5f1 I had to add .git to your suggested string in order for the package manager to resolve it.

"com.unitynative.sharing": "https://github.com/NicholasSheehan/Unity-Native-Sharing.git#release/v1.0.3"

Is what worked, without the .git it wouldn't resolve.

image not saving

image is not saving in external storage but the share dialog box open .please help me to solve this issue

Sending Failed

I just gave this a try, and it works to bring up the share dialog box, but it does not generate a screenshot and when I try to send the generated text, I get a shared failed error.

Using Unity 5.1 and Android 5.

Messenger image sharing doesn't work properly

So I've got a crash on my iPad when I tried to share the image, and an error image not found. For both of those errors I've found a fix on this github but now I have another problem. Whenever I try to share the screenshot on my iPad, it just doesn't show up. It's just a blank square, and when I try to send the image to someone it says "Unable to send this file".
On the iPhone it happens as well, but when I try to re-share the image, the image shows up correctly.

EntryNotFoundException

After cloning this project i try to run and when i try to share by clicking share button then showing this error , why ? what can i do , how can it solve ?
EntryPointNotFoundException: showSocialSharing
NativeShare.CallSocialShareAdvanced (System.String defaultTxt, System.String subject, System.String url, System.String img) (at Assets/Plugins/NativeShare.cs:81)
NativeShare.Share (System.String shareText, System.String imagePath, System.String url, System.String subject) (at Assets/Plugins/NativeShare.cs:40)
NativeShare.ShareScreenshotWithText (System.String text) (at Assets/Plugins/NativeShare.cs:17)
UnityEngine.Events.InvokableCall1[System.String].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:184) UnityEngine.Events.CachedInvokableCall1[System.String].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:302)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:630)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:765)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler](UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()

Error On IPad

The popover View doesn't work on IPad in my case, makes my app crash.
It seems popoverPresentationController need set a non-nil sourceView.
I add some code in IOSNativeShare.m after line 126. It works fine for me. Hope to help.

after this line:
[rootViewController presentViewController:activity animated:YES completion:Nil ];
add:
UIPopoverPresentationController * popContronller=[activity popoverPresentationController]; popContronller.permittedArrowDirections=UIPopoverArrowDirectionDown; popContronller.sourceView=rootViewController.view;

//change location of popover view if you like popContronller.sourceRect=CGRectMake(512,768/2,10,10);

Getting a ClassCastException when sharing an image on Android using GMail

11-21 12:38:15.530: W/Bundle(14891): Key android.intent.extra.STREAM expected Parcelable but value was a java.util.ArrayList. The default value was returned.
11-21 12:38:15.530: W/Bundle(14891): Attempt to cast generated internal exception:
11-21 12:38:15.530: W/Bundle(14891): java.lang.ClassCastException: java.util.ArrayList cannot be cast to android.os.Parcelable
11-21 12:38:15.530: W/Bundle(14891): at android.os.Bundle.getParcelable(Bundle.java:846)
11-21 12:38:15.530: W/Bundle(14891): at android.content.Intent.getParcelableExtra(Intent.java:6761)
11-21 12:38:15.530: W/Bundle(14891): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:9651)
11-21 12:38:15.530: W/Bundle(14891): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1524)
11-21 12:38:15.530: W/Bundle(14891): at android.app.Activity.startActivityForResult(Activity.java:4403)
11-21 12:38:15.530: W/Bundle(14891): at android.app.Activity.startActivityForResult(Activity.java:4362)
11-21 12:38:15.530: W/Bundle(14891): at android.app.Activity.startActivity(Activity.java:4686)
11-21 12:38:15.530: W/Bundle(14891): at android.app.Activity.startActivity(Activity.java:4654)
11-21 12:38:15.530: W/Bundle(14891): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
11-21 12:38:15.530: W/Bundle(14891): at com.unity3d.player.UnityPlayer.c(Unknown Source)
11-21 12:38:15.530: W/Bundle(14891): at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source)
11-21 12:38:15.530: W/Bundle(14891): at android.os.Handler.dispatchMessage(Handler.java:98)
11-21 12:38:15.530: W/Bundle(14891): at android.os.Looper.loop(Looper.java:154)
11-21 12:38:15.530: W/Bundle(14891): at com.unity3d.player.UnityPlayer$c.run(Unknown Source)

Sharing to slack from android build

Title works fine but it gives me "Unable to share file OK" pop up and wont let me send it to slack. It works fine for facebook, instagram, hangout, gmail. Any ideas? Thank you!

Crash with iOS 11.3

Hello after update iOS to 11.3, native sharing is not working anymore.

It was perfectly working before.

image

Share text not working

Guys,
On Facebook i can only share image but i can not share text or url.
On Whatsapp i can only share text so, how can i share url too ?

please guys help me.

Gif Sharing?

Any possibility to share GIF? Mainly to Whatsapp?
Thanks

Trying to update iOSNativeShare.m to work with images and Facebook again

Hi there,

I have no experience with Objective-C and have been working through the night to try and get an in-game highscore image sharing to Facebook again along with the other options. I see the ReadMe has been updated which links to a comment regarding this, but unfortunately this offers no further instructions.

Within initWithText in iOSNativeShare.m I have attempted the following, commenting out the original Activity that has items passed into it.

//Set up the sharing activity and add the items
//UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:Nil];

CustomActivityProvider *ActivityProvider = [[CustomActivityProvider alloc] initWithPlaceholderItem:@""];

CustomActivityProvider is subclass made from these instructions and here and here, but these only seems to handle one thing being shared (string, url, image) for different sharing activities, rather than the array of items I want to use (e.g. 2 things for Facebook and 3 things for Twitter).

Can anyone with more Objective-C experience than me help me out with this? Thanks

All I essentially want to do is make an Activity that takes in 4/5 sharable items within an array, and depending on whether or not it is being shared via Facebook or Twitter, certain items are chosen.

Crash when cancel sharing on Android

How can I catch the event when a player cancels sharing to prevent crashing on Samsung Galaxy Tab 4 and Samsung Galaxy J1 2016. On Samsung Galaxy J7 2016 it works nice.
There is one difference: when there is unhandled exception, the first 2 devices crash, but the third one continues work. So I assume that there appears an exception, so the game crashes.

Instagram Issues

Hello
Great plugin works really well and it's a simple and great solution. I've got some questions:
I am using the plugin but the version with no multiple shares paths, since I have some problems in Android, it works but the Logcat through an exception. So I decided to use the previous version of the plugin and no problems at all. But I have some questions about Instagram and the plugin in general.

  • I test the plugin with Instagram (I can share images and videos!) and it works. When I finish sharing the picture on Instagram it seems that Instagram APP (Android) doesn't close and come back to the Unity App. I checked and this doesn't happen with Facebook for example. My question is, is this depend on the APP or is there any way to force it?
  • Regarding Instagram does anybody know a free plugin to include Instagram for Unity. Instagram API exists but I don't think there is a wrapper for Unity Yet (for free at least).

Thanks in advance

Crash in iOS

Hi,
When I share on iOS, the app crashes with the following message,

Uncaught exception: NSGenericException: Your application has presented a UIActivityViewController (<UIActivityViewController: 0x123f38940>). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.

What could be the issue, I dont know objective C at all.

Thanks in advance,
Altaf

Which social media is selected

Is there any way to find out which app is selected ? for example find out it is Facebook sharing or Twitter sharing. because I want to assign different text to different social media.

Control the position of the pop-up to be above the Share button

Hi! I am using your library for a game I am developing in Unity which is supposed to run on smartphones & tablets on both Android and iOS. I was wondering whether there is any way to position the pop-up sharing window on tablets and iPads to be right above the Share button.

Screenshot 2020-06-24 at 11 03 52

Freezing iPad after click "Share"

I faced the problem with iPad.
https://stackoverflow.com/questions/38323154/unity-game-screenshot-share-in-multiple-social-platform-in-ios/38610345#38610345

Post of Sachin Acharya was very helpful. I just replaced last lines in IOSNativeShare.mm with:

UIActivityViewController *activityVc = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];    

    if(mSubject != NULL) {
        [activityVc setValue:mSubject forKey:@"subject"];
    } else {
        [activityVc setValue:@"" forKey:@"subject"];
    }
    
    if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [activityVc respondsToSelector:@selector(popoverPresentationController)] ) {
        
        UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVc];
        
        [popup presentPopoverFromRect:
         CGRectMake(self.view.frame.size.width/2,
                    self.view.frame.size.height*4/5,
                    0, 0)
                               inView:[UIApplication sharedApplication].keyWindow.rootViewController.view
             permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    } else {
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVc animated:YES completion:nil];
    }

Thanks for nice plugin!

Screenshot error

Hello,

Just wanted to point out an error which is occurring in iOS but not on Android.

The secuence of errors is:

  1. first screenshot share after build says: Error: could not find image, then If I try to share again, this screenshot will be the correct one.
  2. but If I continue playing and try to share again, this screenshot will be the previous one.

So there must be an error in the secuence where the screenshot is saved. I tried an system.IO.Delete previous screenshot but this will render an "ERROR coundnt find image" all the times I try sharing.

I think this error is caused because the share has to wait until the screenshot is created and it isnt doing it at the moment.

Add windows uwp support.

I already did it, but I modified the code for my specific project.

Here is the code that works for me, you can take the uwp part and test it on windows machine.

Tested on Unity 2017.2.0f3, windows 10 1709 (creator's fall update)

using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Runtime.InteropServices;
#if UNITY_UWP
using Windows.Storage.Streams;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using System.Threading.Tasks;
#endif

/*
 * https://github.com/ChrisMaire/unity-native-sharing 
 */

public class NativeShare
{
	public const string MIME_IMAGE = "image/png";
	public const string MIME_TEXT = "text/plain";
	public const string MIME_HTML = "text/html";

	public static void Share(string shareText, string imagePath, string url = null, string mimetype = MIME_IMAGE, string subject = "")
	{
		bool canShare = false;

#if UNITY_ANDROID || UNITY_EDITOR
		canShare = true;
		ShareAndroid(shareText, subject, url, imagePath, mimetype);
#endif
#if UNITY_IOS || UNITY_EDITOR
		canShare = true;
		ShareIOS(shareText, imagePath, url, subject);
#endif
#if UNITY_UWP
		canShare = true;
		UnityEngine.WSA.Application.InvokeOnUIThread(async () => { await ShareUWP(shareText, imagePath, url, subject); }, true);
#endif
		if (!canShare)
			Debug.Log("No sharing set up for this platform.");
	}

#if UNITY_ANDROID || UNITY_EDITOR
	private static void ShareAndroid(string body, string subject, string url, string filePath, string mimeType)
	{
		using (AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"))
		using (AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"))
		{
			using (intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")))
			{ }
			using (intentObject.Call<AndroidJavaObject>("setType", mimeType))
			{ }
			using (intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject))
			{ }
			using (intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), body))
			{ }

			if (!string.IsNullOrEmpty(url))
			{
				// attach url
				using (AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"))
				using (AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", url))
				using (intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject))
				{ }
			}
			else if (!string.IsNullOrEmpty(filePath))
			{
				using (AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"))
				using (AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + filePath))
				using (intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject))
				{ }
			}

			// finally start application
			using (AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
			using (AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"))
			{
				AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, string.Empty);
				currentActivity.Call("startActivity", jChooser);
			}
		}
	}
#endif

	private static void ShareIOS(string shareText, string imagePath, string url, string subject = "")
	{
#if UNITY_IOS || UNITY_EDITOR
		CallSocialShareAdvanced(shareText, subject, url, imagePath);
#endif
	}

#if UNITY_UWP
	private static async Task ShareUWP(string shareText, string imagePath, string url, string subject = "")
	{
		try
		{
			RandomAccessStreamReference streamRef = null;
			if (!string.IsNullOrEmpty(imagePath))
			{
				imagePath = imagePath.Replace("/", "\\");
				StorageFile sFile = await StorageFile.GetFileFromPathAsync(imagePath);
				streamRef = RandomAccessStreamReference.CreateFromFile(sFile);
			}
			DataTransferManager dtm = DataTransferManager.GetForCurrentView();
			dtm.DataRequested +=
				(sender, args) =>
				{
					DataRequest dr = args.Request;
					DataRequestDeferral def = dr.GetDeferral();
					dr.Data.SetText(shareText);
					if (streamRef != null)
						dr.Data.SetBitmap(streamRef);
					else if (!string.IsNullOrEmpty(url))
						dr.Data.SetWebLink(new Uri(url));
					dr.Data.Properties.Title = string.IsNullOrEmpty(subject) ? "Share" : subject;
					dr.Data.Properties.Description = shareText;
					def.Complete();
				};
			DataTransferManager.ShowShareUI();
		}
		catch (Exception ee)
		{
			Debug.LogError("ShareUWP error=" + ee.Message);
		}
	}
#endif

#if UNITY_IOS || UNITY_EDITOR
	private struct ConfigStruct
	{
		public string title;
		public string message;
	}

	[DllImport("__Internal")] private static extern void showAlertMessage(ref ConfigStruct conf);

	private struct SocialSharingStruct
	{
		public string text;
		public string subject;
		public string filePaths;
	}

	[DllImport("__Internal")] private static extern void showSocialSharing(ref SocialSharingStruct conf);

	private static void CallSocialShare(string title, string message)
	{
		ConfigStruct conf = new ConfigStruct();
		conf.title = title;
		conf.message = message;
		showAlertMessage(ref conf);
	}

	private static void CallSocialShareAdvanced(string body, string subject, string url, string filePath)
	{
		SocialSharingStruct conf = new SocialSharingStruct();
		conf.text = body;
		string paths = string.Join(";", filePath);
		if (string.IsNullOrEmpty(paths))
			paths = url;
		else if (!string.IsNullOrEmpty(url))
			paths += ";" + url;
		conf.filePaths = paths;
		conf.subject = subject;

		showSocialSharing(ref conf);
	}
#endif

}

Android Video Share

I am able to share Image and URLs. But if I try to share and mp4 video file I get an error pop up saying file format not supported.

I have kept mime type to video/mp4.

Any help will be grateful. Thanks

screenshot not attached on Telegram

Hi dear
[space]
version: unity 5.6
OS: android
target: telegram
device: Samsung galaxy note 5
[comment]
screenshot make but not attached on Telegram . also in Instagram message me that "unable to load image".
please guide me .

Conflicting types for 'ShowAlertMessage'

Its giving me a "Conflicting types for 'ShowAlertMessage' "
There are actually two ShowAlertMessage in the iOSNativeShare.m but since it works for everyone else could you tell me what might cause this issue? iOSNativeShare.m and .h are both unchanged

Not opening Facebook automatically

The plugin works really good.

The only issue I am having is when I click share, it opens up apps to select from, then I have to click facebook so it shares on Facebook.

How can I make it open Facebook automatically?

Text Sharing

Hi, Thanks for this plugin development.
I want to share text for android and iOS games.

So how to do that? I tried this but this not seam easy to me.
Please give some help in this.

[Android] Crash on launch

Hi I'm experience this issue
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider"

And I fint in your plugin manifest this field
image

As I research there is a way to fix it is change it into this

image

Is this true or am I doing something wrong ?

iOS video share

In's not actualy an issue, just want to ask u. is it possible to share video file via your plagin? Becouse we tried to share video file on android and it works. But in iOS it's always an error. We think that in objectiv-c code there is some class or method witch converts bytes array only to image format

Image Not Found in IPHONE :(

The error I'm getting on the phone is "Image not found" (but everything else, including title, text, and link, are working)
Help me please!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.