This commit is contained in:
sung-su.kim 2019-11-14 16:52:18 +09:00
Родитель 4c100878dd
Коммит 6d3d63fcfe
5 изменённых файлов: 110 добавлений и 1 удалений

Просмотреть файл

@ -7,6 +7,7 @@
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
<privileges>
<privilege>http://tizen.org/privilege/appdir.shareddata</privilege>
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
<privilege>http://tizen.org/privilege/externalstorage</privilege>
<privilege>http://tizen.org/privilege/haptic</privilege>
@ -17,6 +18,7 @@
<privilege>http://tizen.org/privilege/mediastorage</privilege>
<privilege>http://tizen.org/privilege/message.read</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/externalstorage.appdata</privilege>
</privileges>
<provides-appdefined-privileges />
<feature name="http://tizen.org/feature/location">true</feature>

Просмотреть файл

@ -71,7 +71,8 @@ namespace Samples.ViewModel
{
{ DevicePlatform.iOS, new[] { "public.my.comic.extension" } }, // or general UTType values
{ DevicePlatform.Android, new[] { "application/comics" } },
{ DevicePlatform.UWP, new[] { ".cbr", ".cbz" } }
{ DevicePlatform.UWP, new[] { ".cbr", ".cbz" } },
{ DevicePlatform.Tizen, new[] { "*/*" } },
});
var options = new PickOptions

Просмотреть файл

@ -0,0 +1,100 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Tizen.Applications;
namespace Xamarin.Essentials
{
public static partial class FilePicker
{
static Task<FilePickerResult> PlatformPickFileAsync(PickOptions options)
{
Permissions.EnsureDeclared(PermissionType.LaunchApp);
Permissions.EnsureDeclared(PermissionType.ReadExternalStorage);
var tcs = new TaskCompletionSource<FilePickerResult>();
var appControl = new AppControl();
appControl.Operation = AppControlOperations.Pick;
appControl.ExtraData.Add(AppControlData.SectionMode, "single");
appControl.LaunchMode = AppControlLaunchMode.Single;
var fileType = options?.FileTypes?.Value?.FirstOrDefault();
if (fileType == null)
{
appControl.Mime = "*/*";
}
else
{
appControl.Mime = fileType;
}
AppControl.SendLaunchRequest(appControl, (request, reply, result) =>
{
var pr = new FilePickerResult(new List<string>());
if (result == AppControlReplyResult.Succeeded)
{
if (reply.ExtraData.Count() > 0)
{
pr = new FilePickerResult(reply.ExtraData.Get<IEnumerable<string>>(AppControlData.Selected).ToList());
}
}
tcs.TrySetResult(pr);
});
return tcs.Task;
}
}
public partial class FilePickerFileType
{
public static FilePickerFileType PlatformImageFileType() =>
new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.Tizen, new[] { "image/*" } },
});
public static FilePickerFileType PlatformPngFileType() =>
new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.Tizen, new[] { "image/png" } }
});
}
public partial class PickerResultBase
{
readonly string fullPath;
internal PickerResultBase(IList<string> list)
{
if (list != null)
{
foreach (var path in list)
{
fullPath = path;
FileName = string.Empty;
if (path.Count() > 0)
{
FileName = Path.GetFileName(path);
}
}
}
}
async Task<Stream> PlatformOpenReadStreamAsync()
{
await Permissions.RequestAsync(PermissionType.ReadExternalStorage);
var stream = File.Open(fullPath, FileMode.Open, FileAccess.Read);
return Task.FromResult<Stream>(stream).Result;
}
}
public partial class FilePickerResult
{
internal FilePickerResult(IList<string> list)
: base(list)
{
}
}
}

Просмотреть файл

@ -100,6 +100,12 @@ namespace Xamarin.Essentials
privileges.Add(("http://tizen.org/privilege/internet", false));
privileges.Add(("http://tizen.org/privilege/network.get", false));
break;
case PermissionType.ReadExternalStorage:
privileges.Add(("http://tizen.org/privilege/appdir.shareddata", false));
privileges.Add(("http://tizen.org/privilege/externalstorage", true));
privileges.Add(("http://tizen.org/privilege/externalstorage.appdata", false));
privileges.Add(("http://tizen.org/privilege/mediastorage", true));
break;
case PermissionType.Vibrate:
privileges.Add(("http://tizen.org/privilege/haptic", false));
break;