Skip to content

Commit

Permalink
v1.0.6 Added optional mime type for Android sharing intents
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasSheehan committed May 8, 2021
1 parent 0739e96 commit aae5e81
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Adapters/AndroidUnityNativeSharingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public AndroidUnityNativeSharingAdapter()
sharingJavaClass = new AndroidJavaClass(AndroidClass);
}

public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*")
{
AndroidJNI.AttachCurrentThread();

sharingJavaClass.CallStatic(ShareScreenshotWithTextMethodName, shareText, filePath, showShareDialogBox, shareDialogBoxText);
sharingJavaClass.CallStatic(ShareScreenshotWithTextMethodName, shareText, filePath, showShareDialogBox, shareDialogBoxText, mimeType);
}

public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
Expand Down
2 changes: 1 addition & 1 deletion Adapters/IUnityNativeSharingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace UnityNative.Sharing
{
public interface IUnityNativeSharingAdapter
{
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With");
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*");
void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With");
}
}
2 changes: 1 addition & 1 deletion Adapters/IosUnityNativeSharingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IosUnityNativeSharingAdapter : IUnityNativeSharingAdapter
[System.Runtime.InteropServices.DllImport("__Internal")]
private static extern void UnityNative_Sharing_ShareText(string shareText);

public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*")
{
UnityNative_Sharing_ShareTextAndScreenshot(shareText, filePath);
}
Expand Down
2 changes: 1 addition & 1 deletion Adapters/NullUnityNativeSharingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace UnityNative.Sharing
{
public class NullUnityNativeSharingAdapter : IUnityNativeSharingAdapter
{
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*")
{
}

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.0.6] - 2021-03-09
### Added
- Added optional mime type parameter for Android to use in the intent rather than it being hardcoded to `image/*`

## [1.0.5] - 2021-01-07
### Fixed
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Plugins/Android/src~/Unity-Native-Sharing/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

ext.outputDir = "..\\.."
ext.outputName = "com.UnityNative.Sharing-v1.0.5"
ext.outputName = "com.UnityNative.Sharing-v1.0.6"

android {
compileSdkVersion 28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public class UnityNativeSharingAdapter {
* @param imagePath - Path to the file to share
* @param showShareDialog - Should the share dialog be opened
* @param shareDialogBoxText - Title of the share dialog
* @param mimeType - Mime type of the file being shared
*/
@Keep
public static void ShareScreenshotAndText(String shareText, String imagePath, boolean showShareDialog, String shareDialogBoxText) {
public static void ShareScreenshotAndText(String shareText, String imagePath, boolean showShareDialog, String shareDialogBoxText, String mimeType) {

//Generate the intent
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_TEXT, shareText);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Examples can be found at [Unity-Native-Example-Project](https://github.com/Nicho

![AddPackageFromGitURL](Images~/AddPackageFromGitURL.PNG)

`https://github.com/NicholasSheehan/Unity-Native-Sharing.git#v1.0.5`
`https://github.com/NicholasSheehan/Unity-Native-Sharing.git#v1.0.6`

<h2 align="center">Unity 2018.3 or later (Using Unity Package Manager)</h2>

Expand All @@ -50,7 +50,7 @@ Add this to the projects `manifest.json`

To update the package, change suffix `#{version}` to the target version.

* e.g. `"com.unitynative.sharing" : "https://github.com/NicholasSheehan/Unity-Native-Sharing.git#v1.0.5"`
* e.g. `"com.unitynative.sharing" : "https://github.com/NicholasSheehan/Unity-Native-Sharing.git#v1.0.6"`

<h2 align="center">Unity 2018.3 or later (Using OpenUPM)</h2>

Expand Down
7 changes: 4 additions & 3 deletions UnityNativeSharing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IUnityNativeSharing
{
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With");
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*");
void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With");
}

Expand Down Expand Up @@ -38,9 +38,10 @@ public UnityNativeSharing(IUnityNativeSharingAdapter adapter)
/// <param name="filePath">The path to the attached file</param>
/// <param name="showShareDialogBox">Should the share dialog be opened (Android only)</param>
/// <param name="shareDialogBoxText">The text to show on the share dialog (Android only)</param>
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
/// <param name="mimeType">Mime type of the file being shared (Android only)</param>
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*")
{
adapter.ShareScreenshotAndText(shareText, filePath, showShareDialogBox, shareDialogBoxText);
adapter.ShareScreenshotAndText(shareText, filePath, showShareDialogBox, shareDialogBoxText, mimeType);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.unitynative.sharing",
"version": "1.0.5",
"version": "1.0.6",
"displayName": "Unity-Native-Sharing",
"description": "A Unity plugin to open native sharing dialogs on iOS and Android",
"unity": "2018.3",
Expand Down

0 comments on commit aae5e81

Please sign in to comment.