SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [assembly: Xamarin.Forms.Dependency(typeof(MediaService))]
  2. namespace MultiImagePicker.Droid
  3. {
  4.     public class MediaService : Java.Lang.Object, IMediaService
  5.     {
  6.         public static int OPENGALLERYCODE = 100;
  7.         public void OpenGallery()
  8.         {
  9.             try
  10.             {
  11.                 var imageIntent = new Intent(Intent.ActionPick);
  12.                 imageIntent.SetType("image/*");
  13.                 imageIntent.PutExtra(Intent.ExtraAllowMultiple, true);
  14.                 imageIntent.SetAction(Intent.ActionGetContent);
  15.                 ((Activity)Forms.Context).StartActivityForResult(Intent.CreateChooser(imageIntent, "Select photo"), OPENGALLERYCODE);
  16.                 Toast.MakeText(Xamarin.Forms.Forms.Context, "Tap and hold to select multiple photos.", ToastLength.Short).Show();
  17.             }
  18.             catch (Exception ex)
  19.             {
  20.                 Console.WriteLine(ex.ToString());
  21.                 Toast.MakeText(Xamarin.Forms.Forms.Context, "Error. Can not continue, try again.", ToastLength.Long).Show();
  22.             }
  23.         }
  24.  
  25.         /// <summary>
  26.         ///     Call this when you want to delete our temporary images.
  27.         ///     Recommendation: Call this after successfully uploading images to Azure Blob Storage.
  28.         /// </summary>
  29.         void IMediaService.ClearFileDirectory()
  30.         {
  31.             var directory = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures), ImageHelpers.collectionName).Path.ToString();
  32.  
  33.             if (Directory.Exists(directory))
  34.             {
  35.                 var list = Directory.GetFiles(directory, "*");
  36.                 if (list.Length > 0)
  37.                 {
  38.                     for (int i = 0; i < list.Length; i++)
  39.                     {
  40.                         File.Delete(list[i]);
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.  
  46.         /*
  47.         Example of how to call ClearFileDirectory():
  48.  
  49.             if (Device.RuntimePlatform == Device.Android)
  50.             {
  51.                 DependencyService.Get<IMediaService>().ClearFileDirectory();
  52.             }
  53.             if (Device.RuntimePlatform == Device.iOS)
  54.             {
  55.                 GMMultiImagePicker.Current.ClearFileDirectory();
  56.             }
  57.  
  58.         */
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top