diff --git a/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShare.java b/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShare.java index a819f6f..ba41c1b 100644 --- a/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShare.java +++ b/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShare.java @@ -37,7 +37,7 @@ public class NativeShare private static int isXiaomiOrMIUI = 0; // 1: true, -1: false - public static void Share( final Context context, final NativeShareResultReceiver shareResultReceiver, final String[] targetPackages, final String[] targetClasses, final String[] files, final String[] mimes, final String subject, final String text, final String title ) + public static void Share( final Context context, final NativeShareResultReceiver shareResultReceiver, final String[] targetPackages, final String[] targetClasses, final String[] files, final String[] mimes, final String[] emailRecipients, final String subject, final String text, final String title ) { if( files.length > 0 && GetAuthority( context ) == null ) { @@ -55,6 +55,7 @@ public static void Share( final Context context, final NativeShareResultReceiver bundle.putString( NativeShareFragment.TITLE_ID, title ); bundle.putStringArrayList( NativeShareFragment.FILES_ID, ConvertArrayToArrayList( files ) ); bundle.putStringArrayList( NativeShareFragment.MIMES_ID, ConvertArrayToArrayList( mimes ) ); + bundle.putStringArrayList( NativeShareFragment.EMAIL_RECIPIENTS_ID, ConvertArrayToArrayList( emailRecipients ) ); bundle.putStringArrayList( NativeShareFragment.TARGET_PACKAGE_ID, ConvertArrayToArrayList( targetPackages ) ); bundle.putStringArrayList( NativeShareFragment.TARGET_CLASS_ID, ConvertArrayToArrayList( targetClasses ) ); @@ -100,6 +101,7 @@ public static Intent CreateIntentFromBundle( Context context, Bundle bundle, Arr final String title = bundle.getString( NativeShareFragment.TITLE_ID ); final ArrayList files = bundle.getStringArrayList( NativeShareFragment.FILES_ID ); final ArrayList mimes = bundle.getStringArrayList( NativeShareFragment.MIMES_ID ); + final ArrayList emailRecipients = bundle.getStringArrayList( NativeShareFragment.EMAIL_RECIPIENTS_ID ); final ArrayList targetPackages = bundle.getStringArrayList( NativeShareFragment.TARGET_PACKAGE_ID ); final ArrayList targetClasses = bundle.getStringArrayList( NativeShareFragment.TARGET_CLASS_ID ); @@ -194,6 +196,13 @@ else if( !mimeSubtype.equals( thisMimeSubtype ) ) intent.setAction( Intent.ACTION_SEND ); } + if( emailRecipients.size() > 0 ) + { + String[] emailRecipientsArray = new String[emailRecipients.size()]; + emailRecipients.toArray( emailRecipientsArray ); + intent.putExtra( Intent.EXTRA_EMAIL, emailRecipientsArray ); + } + if( title.length() > 0 ) intent.putExtra( Intent.EXTRA_TITLE, title ); diff --git a/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShareFragment.java b/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShareFragment.java index f3530f8..e5090dc 100644 --- a/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShareFragment.java +++ b/.github/AAR Source (Android)/java/com/yasirkula/unity/NativeShareFragment.java @@ -28,6 +28,7 @@ public class NativeShareFragment extends Fragment public static final String TARGET_CLASS_ID = "NS_TARGET_CLASS"; public static final String FILES_ID = "NS_FILES"; public static final String MIMES_ID = "NS_MIMES"; + public static final String EMAIL_RECIPIENTS_ID = "NS_EMAIL_RECIPIENTS"; public static final String SUBJECT_ID = "NS_SUBJECT"; public static final String TEXT_ID = "NS_TEXT"; public static final String TITLE_ID = "NS_TITLE"; @@ -45,6 +46,8 @@ public void onCreate( Bundle savedInstanceState ) final Intent shareIntent = NativeShare.CreateIntentFromBundle( getActivity(), getArguments(), fileUris ); final String title = getArguments().getString( NativeShareFragment.TITLE_ID ); + shareIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); + try { Intent chooserIntent; diff --git a/.github/README.md b/.github/README.md index 5f3229a..bd5ccb4 100644 --- a/.github/README.md +++ b/.github/README.md @@ -44,6 +44,7 @@ Simply create a new **NativeShare** object and customize it by chaining the foll - `SetUrl( string url )`: sets the shared url. On supported iOS apps, this url is used to generate a preview of the target webpage. Other iOS apps may append the url to the text or omit it. While sharing a file on iOS or while sharing anything on Android, the url is appended to the text (unless the text already contains the url) - `AddFile( string filePath, string mime = null )`: adds the file at path to the share action. You can add multiple files of different types. The MIME of the file is automatically determined if left null; however, if the file doesn't have an extension and/or you already know the MIME of the file, you can enter the MIME manually. MIME has no effect on iOS - `AddFile( Texture2D texture, string createdFileName = "Image.png" )`: saves the *texture* to *Application.temporaryCachePath* with the specified filename and adds the image file to the share action +- `AddEmailRecipient( string emailAddress )`: auto-populates the *recipients* field of e-mail applications on Android platform. Has no effect on iOS - `SetTitle( string title )`: sets the title of the share dialog on Android platform. Has no effect on iOS - `AddTarget( string androidPackageName, string androidClassName = null )`: shares content on a specific application on Android platform. If *androidClassName* is left null, list of activities in the share dialog will be narrowed down to the activities in the specified *androidPackageName* that can handle this share action. Note that androidClassName, if provided, must be the full name of the activity (with its package). You can call this function multiple times. This function has no effect on iOS - `SetCallback( ShareResultCallback callback )`: invokes the *callback* function after the share action is completed. **ShareResultCallback** has the following signature: `void ShareResultCallback( ShareResult result, string shareTarget )` diff --git a/Plugins/NativeShare/Android/NSCallbackHelper.cs b/Plugins/NativeShare/Android/NSCallbackHelper.cs index b729931..94d57f5 100644 --- a/Plugins/NativeShare/Android/NSCallbackHelper.cs +++ b/Plugins/NativeShare/Android/NSCallbackHelper.cs @@ -1,4 +1,5 @@ #if UNITY_EDITOR || UNITY_ANDROID +using System.Collections; using UnityEngine; namespace NativeShareNamespace @@ -35,11 +36,12 @@ private void Update() } } - private void OnApplicationFocus( bool focus ) + private IEnumerator OnApplicationFocus( bool focus ) { if( focus ) { // Share sheet is closed and now Unity activity is running again. Send Unknown result if OnShareCompleted wasn't called + yield return null; resultReceived = true; } } diff --git a/Plugins/NativeShare/Android/NativeShare.aar b/Plugins/NativeShare/Android/NativeShare.aar index 5fbd3f5..84f2dc9 100644 Binary files a/Plugins/NativeShare/Android/NativeShare.aar and b/Plugins/NativeShare/Android/NativeShare.aar differ diff --git a/Plugins/NativeShare/NativeShare.cs b/Plugins/NativeShare/NativeShare.cs index 569b7fa..f27e814 100644 --- a/Plugins/NativeShare/NativeShare.cs +++ b/Plugins/NativeShare/NativeShare.cs @@ -51,6 +51,10 @@ private static AndroidJavaObject Context private string title = string.Empty; private string url = string.Empty; +#if UNITY_EDITOR || UNITY_ANDROID + private readonly List emailRecipients = new List( 0 ); +#endif + #if UNITY_EDITOR || UNITY_ANDROID private readonly List targetPackages = new List( 0 ); private readonly List targetClasses = new List( 0 ); @@ -162,6 +166,16 @@ public NativeShare AddFile( Texture2D texture, string createdFileName = "Image.p return this; } + public NativeShare AddEmailRecipient( string emailAddress ) + { +#if UNITY_EDITOR || UNITY_ANDROID + if( !string.IsNullOrEmpty( emailAddress ) && !emailRecipients.Contains( emailAddress ) ) + emailRecipients.Add( emailAddress ); +#endif + + return this; + } + public void Share() { if( files.Count == 0 && subject.Length == 0 && text.Length == 0 && url.Length == 0 ) @@ -176,7 +190,7 @@ public void Share() if( callback != null ) callback( ShareResult.Shared, null ); #elif UNITY_ANDROID - AJC.CallStatic( "Share", Context, new NSShareResultCallbackAndroid( callback ), targetPackages.ToArray(), targetClasses.ToArray(), files.ToArray(), mimes.ToArray(), subject, CombineURLWithText(), title ); + AJC.CallStatic( "Share", Context, new NSShareResultCallbackAndroid( callback ), targetPackages.ToArray(), targetClasses.ToArray(), files.ToArray(), mimes.ToArray(), emailRecipients.ToArray(), subject, CombineURLWithText(), title ); #elif UNITY_IOS NSShareResultCallbackiOS.Initialize( callback ); if( files.Count == 0 ) diff --git a/Plugins/NativeShare/README.txt b/Plugins/NativeShare/README.txt index 5febdcd..76afe8d 100644 --- a/Plugins/NativeShare/README.txt +++ b/Plugins/NativeShare/README.txt @@ -49,6 +49,7 @@ Simply create a new NativeShare object and customize it by chaining the followin - SetUrl( string url ): sets the shared url. On supported iOS apps, this url is used to generate a preview of the target webpage. Other iOS apps may append the url to the text or omit it. While sharing a file on iOS or while sharing anything on Android, the url is appended to the text (unless the text already contains the url) - AddFile( string filePath, string mime = null ): adds the file at path to the share action. You can add multiple files of different types. The MIME of the file is automatically determined if left null; however, if the file doesn't have an extension and/or you already know the MIME of the file, you can enter the MIME manually. MIME has no effect on iOS - AddFile( Texture2D texture, string createdFileName = "Image.png" ): saves the texture to Application.temporaryCachePath with the specified filename and adds the image file to the share action +- AddEmailRecipient( string emailAddress ): auto-populates the recipients field of e-mail applications on Android platform. Has no effect on iOS - SetTitle( string title ): sets the title of the share dialog on Android platform. Has no effect on iOS - AddTarget( string androidPackageName, string androidClassName = null ): shares content on a specific application on Android platform. If androidClassName is left null, list of activities in the share dialog will be narrowed down to the activities in the specified androidPackageName that can handle this share action. Note that androidClassName, if provided, must be the full name of the activity (with its package). You can call this function multiple times. This function has no effect on iOS - SetCallback( ShareResultCallback callback ): invokes the callback function after the share action is completed. ShareResultCallback has the following signature: void ShareResultCallback( ShareResult result, string shareTarget ) diff --git a/package.json b/package.json index 0893dcf..92ec363 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.nativeshare", "displayName": "Native Share", - "version": "1.4.6", + "version": "1.4.7", "documentationUrl": "https://github.com/yasirkula/UnityNativeShare", "changelogUrl": "https://github.com/yasirkula/UnityNativeShare/releases", "licensesUrl": "https://github.com/yasirkula/UnityNativeShare/blob/master/LICENSE.txt",