-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DataTransferManager support on Android
- Loading branch information
1 parent
bfe6ec9
commit 4c2e6dd
Showing
8 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Android.Content; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Extensions; | ||
using Uno.UI; | ||
|
||
namespace Windows.ApplicationModel.DataTransfer | ||
{ | ||
public partial class DataTransferManager | ||
{ | ||
public static bool IsSupported() => true; | ||
|
||
private static async Task<bool> ShowShareUIAsync(ShareUIOptions options, DataPackage dataPackage) | ||
{ | ||
var context = ContextHelper.Current; | ||
if (context == null) | ||
{ | ||
if (_instance.Value.Log().IsEnabled(LogLevel.Error)) | ||
{ | ||
_instance.Value.Log().LogError("The Share API was called too early in the application lifecycle"); | ||
} | ||
return false; | ||
} | ||
|
||
var dataPackageView = dataPackage.GetView(); | ||
var items = new List<string>(); | ||
|
||
if (dataPackageView.Contains(StandardDataFormats.Text)) | ||
{ | ||
var text = await dataPackageView.GetTextAsync(); | ||
items.Add(text); | ||
} | ||
|
||
var uri = await GetSharedUriAsync(dataPackageView); | ||
if (uri != null) | ||
{ | ||
items.Add(uri.ToString()); | ||
} | ||
|
||
var intent = new Intent(Intent.ActionSend); | ||
intent.SetType("text/plain"); | ||
intent.PutExtra(Intent.ExtraText, string.Join(Environment.NewLine, items)); | ||
|
||
var title = dataPackage.Properties.Title; | ||
if (!string.IsNullOrWhiteSpace(title)) | ||
{ | ||
intent.PutExtra(Intent.ExtraSubject, title); | ||
} | ||
|
||
var chooserIntent = Intent.CreateChooser(intent, title ?? string.Empty); | ||
var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; | ||
chooserIntent?.SetFlags(flags); | ||
ContextHelper.Current.StartActivity(chooserIntent); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.other.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters