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

Commit

Permalink
Merge pull request #948 from jamesmontemagno/net6
Browse files Browse the repository at this point in the history
Net6
  • Loading branch information
jamesmontemagno authored Sep 20, 2022
2 parents 3e038b3 + d320c8a commit d87341a
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v12.0</TargetFrameworkVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down Expand Up @@ -57,7 +57,7 @@
<Version>2.1.1.648</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
<Version>1.7.1</Version>
<Version>1.7.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.media" android:installLocation="auto">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="30" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="32" />
<application android:label="Media.Plugin.Sample.Android">
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Essentials">
<Version>1.7.1</Version>
<Version>1.7.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Essentials">
<Version>1.7.1</Version>
<Version>1.7.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Essentials" Version="1.7.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />
</ItemGroup>
Expand Down
18 changes: 0 additions & 18 deletions src/Media.Plugin/Android/CustomPermissions.cs

This file was deleted.

5 changes: 1 addition & 4 deletions src/Media.Plugin/Android/ManifestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
using Android.App;

[assembly: UsesFeature("android.hardware.camera", Required = false)]
[assembly: UsesFeature("android.hardware.camera.autofocus", Required = false)]

[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
[assembly: UsesPermission("android.permission.READ_EXTERNAL_STORAGE")]
[assembly: UsesFeature("android.hardware.camera.autofocus", Required = false)]
49 changes: 0 additions & 49 deletions src/Media.Plugin/Android/MediaImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ bool IsValidExif(ExifInterface exif)
/// <returns>Media file or null if canceled</returns>
public async Task<MediaFile> PickPhotoAsync(PickMediaOptions options = null, CancellationToken token = default(CancellationToken))
{
if (!(await RequestStoragePermission()))
{
throw new MediaPermissionException(nameof(StoragePermission));
}
var media = await TakeMediaAsync("image/*", Intent.ActionPick, null, token);

if (options == null)
Expand All @@ -117,11 +113,6 @@ bool IsValidExif(ExifInterface exif)

public async Task<List<MediaFile>> PickPhotosAsync(PickMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken))
{
if (!await RequestStoragePermission())
{
return null;
}

var medias = await TakeMediasAsync("image/*", Intent.ActionPick, new StorePickerMediaOptions { MultiPicker = true }, token);

if (medias == null)
Expand Down Expand Up @@ -274,11 +265,6 @@ async Task FixOrientationAndResize(PickMediaOptions options, MediaFile media)
public async Task<MediaFile> PickVideoAsync(CancellationToken token = default(CancellationToken))
{

if (!(await RequestStoragePermission()))
{
throw new MediaPermissionException(nameof(StoragePermission));
}

return await TakeMediaAsync("video/*", Intent.ActionPick, null, token);
}

Expand Down Expand Up @@ -318,8 +304,6 @@ async Task<bool> RequestCameraPermissions()

var checkCamera = HasPermissionInManifest(Android.Manifest.Permission.Camera);

var hasStoragePermission = await Permissions.CheckStatusAsync<StoragePermission>();

var hasCameraPermission = PermissionStatus.Granted;
if (checkCamera)
hasCameraPermission = await Permissions.CheckStatusAsync<Permissions.Camera>();
Expand All @@ -328,14 +312,11 @@ async Task<bool> RequestCameraPermissions()
var permissions = new List<string>();

var camera = nameof(Permissions.Camera);
var storage = nameof(StoragePermission);


if (hasCameraPermission != PermissionStatus.Granted)
permissions.Add(camera);

if (hasStoragePermission != PermissionStatus.Granted)
permissions.Add(storage);

if (permissions.Count == 0) //good to go!
return true;
Expand All @@ -348,19 +329,9 @@ async Task<bool> RequestCameraPermissions()
case nameof(Permissions.Camera):
results.Add(permission, await Permissions.RequestAsync<Permissions.Camera>());
break;
case nameof(StoragePermission):
results.Add(permission, await Permissions.RequestAsync<StoragePermission>());
break;
}
}

if (results.ContainsKey(storage) &&
results[storage] != PermissionStatus.Granted)
{
Console.WriteLine("Storage permission Denied.");
return false;
}

if (results.ContainsKey(camera) &&
results[camera] != PermissionStatus.Granted)
{
Expand All @@ -371,26 +342,6 @@ async Task<bool> RequestCameraPermissions()
return true;
}

async Task<bool> RequestStoragePermission()
{
//We always have permission on anything lower than marshmallow.
if ((int)Build.VERSION.SdkInt < 23)
return true;

var status = await Permissions.CheckStatusAsync<StoragePermission>();
if (status != PermissionStatus.Granted)
{
Console.WriteLine("Does not have storage permission granted, requesting.");
var result = await Permissions.RequestAsync<StoragePermission>();
if (result != PermissionStatus.Granted)
{
Console.WriteLine("Storage permission Denied.");
return false;
}
}

return true;
}

IList<string> requestedPermissions;
bool HasPermissionInManifest(string permission)
Expand Down
2 changes: 1 addition & 1 deletion src/Media.Plugin/Media.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</PropertyGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.7.0.2" />
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.6.0.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<Compile Include="**\Android\*.cs" />
</ItemGroup>
Expand Down
Loading

0 comments on commit d87341a

Please sign in to comment.