Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
- Potential bugfix for ShareResultCallback.shareTarget being null for…
Browse files Browse the repository at this point in the history
… some apps on newest Android versions

- Potential bugfix for crash in Unity as a Library apps (#155)
- Added NativeShare.Clear function
  • Loading branch information
yasirkula committed Dec 10, 2022
1 parent bfb8b4e commit 25205f4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public static IntentSender Initialize( Context context )
// Maybe FLAG_IMMUTABLE is sufficient but the pre-31 default value was implicitly mutable and I don't trust
// all social apps to work correctly on Android 12+ (API 31+) if I set it to FLAG_IMMUTABLE
//pendingIntentFlags |= PendingIntent.FLAG_MUTABLE;

// Only temporarily set the IMMUTABLE flag to avoid crashes until Android 12 SDK is officially released
// https://github.com/yasirkula/UnityNativeShare/issues/130
pendingIntentFlags |= PendingIntent.FLAG_IMMUTABLE;
pendingIntentFlags |= 1 << 25; // Hardcoded value of PendingIntent.FLAG_MUTABLE (when compiling with an older SDK version)
}

return PendingIntent.getBroadcast( context, 0, receiverIntent, pendingIntentFlags ).getIntentSender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;

import org.xmlpull.v1.XmlPullParserException;
Expand Down Expand Up @@ -254,12 +255,19 @@ private static PathStrategy parsePathStrategy(Context context, String authority)
final SimplePathStrategy strat = new SimplePathStrategy(authority);
final ProviderInfo info = context.getPackageManager()
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
final XmlResourceParser in = info.loadXmlMetaData(
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
//if (in == null) {
// throw new IllegalArgumentException(
// "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
//}
if (info == null)
{
Log.w("Unity", "NativeShareContentProvider.resolveContentProvider is null!");
}
else
{
final XmlResourceParser in = info.loadXmlMetaData(
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS );
//if (in == null) {
// throw new IllegalArgumentException(
// "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
//}
}

File target = null;
target = buildPath(DEVICE_ROOT, ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onCreate( Bundle savedInstanceState )
super.onCreate( savedInstanceState );

if( NativeShare.shareResultReceiver == null )
getFragmentManager().beginTransaction().remove( this ).commit();
onActivityResult( SHARE_RESULT_CODE, Activity.RESULT_CANCELED, null );
else
{
final ArrayList<Uri> fileUris = new ArrayList<Uri>();
Expand Down
1 change: 1 addition & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ There are two ways to set up the plugin on iOS:

Simply create a new **NativeShare** object and customize it by chaining the following functions as you like (see example code):

- `Clear()`: clears the previously set share content (if any). Only useful if the same NativeShare instance will be reused for memory efficiency
- `SetSubject( string subject )`: sets the subject (primarily used in e-mail applications)
- `SetText( string text )`: sets the shared text. Note that the Facebook app will omit text, if exists (see [this topic](https://stackoverflow.com/a/35102802/2373034))
- `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)
Expand Down
Binary file modified Plugins/NativeShare/Android/NativeShare.aar
Binary file not shown.
19 changes: 17 additions & 2 deletions Plugins/NativeShare/NativeShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ private static AndroidJavaObject Context

#if UNITY_EDITOR || UNITY_ANDROID
private readonly List<string> emailRecipients = new List<string>( 0 );
#endif

#if UNITY_EDITOR || UNITY_ANDROID
private readonly List<string> targetPackages = new List<string>( 0 );
private readonly List<string> targetClasses = new List<string>( 0 );
#endif
Expand All @@ -65,6 +63,23 @@ private static AndroidJavaObject Context

private ShareResultCallback callback;

public NativeShare Clear()
{
subject = text = title = url = string.Empty;

#if UNITY_EDITOR || UNITY_ANDROID
emailRecipients.Clear();
targetPackages.Clear();
targetClasses.Clear();
#endif
files.Clear();
mimes.Clear();

callback = null;

return this;
}

public NativeShare SetSubject( string subject )
{
this.subject = subject ?? string.Empty;
Expand Down
3 changes: 2 additions & 1 deletion Plugins/NativeShare/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Native Share for Android & iOS =
= Native Share for Android & iOS (v1.4.8) =

Online documentation & example code available at: https://github.com/yasirkula/UnityNativeShare
E-mail: [email protected]
Expand Down Expand Up @@ -44,6 +44,7 @@ If you are sure that your plugin is up-to-date, then enable "Custom Proguard Fil
4. SCRIPTING API
Simply create a new NativeShare object and customize it by chaining the following functions as you like:

- Clear(): clears the previously set share content (if any). Only useful if the same NativeShare instance will be reused for memory efficiency
- SetSubject( string subject ): sets the subject (primarily used in e-mail applications)
- SetText( string text ): sets the shared text. Note that the Facebook app will omit text, if exists
- 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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.nativeshare",
"displayName": "Native Share",
"version": "1.4.7",
"version": "1.4.8",
"documentationUrl": "https://github.com/yasirkula/UnityNativeShare",
"changelogUrl": "https://github.com/yasirkula/UnityNativeShare/releases",
"licensesUrl": "https://github.com/yasirkula/UnityNativeShare/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 25205f4

Please sign in to comment.