Karamunting.Android.Alhazmy13.MediaPicker 2.4.0

Xamarin.Android Libary that lets you to select multiple images or video

Install-Package Karamunting.Android.Alhazmy13.MediaPicker -Version 2.4.0
dotnet add package Karamunting.Android.Alhazmy13.MediaPicker --version 2.4.0
<PackageReference Include="Karamunting.Android.Alhazmy13.MediaPicker" Version="2.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Karamunting.Android.Alhazmy13.MediaPicker --version 2.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
// Created by Rofiq Setiawan (rofiqsetiawan@gmail.com)

using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Net.Alhazmy13.MediaPicker;
using Net.Alhazmy13.MediaPicker.Image;
using Fragment = Android.App.Fragment;
using R = MediaPickerDemo.Resource;

namespace MediaPickerDemo
{
    public sealed class ImageFragment : Fragment
    {
        private ImageView _imageView;
        private TextView _path;

        private const string MyTag = "MainActivity";
        private List<string> _pathList;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(R.Layout.image_layout, container, false);

            _imageView = view.FindViewById<ImageView>(R.Id.iv_image);
            _path = view.FindViewById<TextView>(R.Id.tv_path);
            view.FindViewById<Button>(R.Id.bt_pick).Click += (s, e) => PickImage();

            return view;
        }

        private void PickImage()
        {
            new ImagePicker.Builder(Activity)
                .Mode(ImagePicker.Mode.CameraAndGallery)
                .CompressLevel(ImagePicker.ComperesLevel.Medium)
                .Directory(ImagePicker.Directory.Default)
                .Extension(ImagePicker.Extension.Jpg)
                .AllowOnlineImages(false)
                .Scale(600, 600)
                .AllowMultipleImages(true)
                .EnableDebuggingMode(false)
                .Build();
        }

        public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
#if DEBUG
            Log.Debug(
                MyTag,
                $"OnActivityResult() called with: requestCode = [{requestCode}], resultCode = [{resultCode}], data = [{data}]"
            );
#endif
            if (requestCode == ImagePicker.ImagePickerRequestCode && resultCode == Result.Ok)
            {
                // .ToList() available on "Net.Alhazmy13.MediaPicker" namespace
                _pathList = data.GetSerializableExtra(ImagePicker.ExtraImagePath).ToList();

                LoadImage();
            }
        }

        private void LoadImage()
        {
#if DEBUG
            Log.Debug(MyTag, $"LoadImage: {_pathList.Count}");
#endif
            _path.Text = (_pathList[0]);
            _imageView.SetImageBitmap(BitmapFactory.DecodeFile(_pathList[0]));
        }
    }
}
// Created by Rofiq Setiawan (rofiqsetiawan@gmail.com)

using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Net.Alhazmy13.MediaPicker;
using Net.Alhazmy13.MediaPicker.Image;
using Fragment = Android.App.Fragment;
using R = MediaPickerDemo.Resource;

namespace MediaPickerDemo
{
    public sealed class ImageFragment : Fragment
    {
        private ImageView _imageView;
        private TextView _path;

        private const string MyTag = "MainActivity";
        private List<string> _pathList;

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(R.Layout.image_layout, container, false);

            _imageView = view.FindViewById<ImageView>(R.Id.iv_image);
            _path = view.FindViewById<TextView>(R.Id.tv_path);
            view.FindViewById<Button>(R.Id.bt_pick).Click += (s, e) => PickImage();

            return view;
        }

        private void PickImage()
        {
            new ImagePicker.Builder(Activity)
                .Mode(ImagePicker.Mode.CameraAndGallery)
                .CompressLevel(ImagePicker.ComperesLevel.Medium)
                .Directory(ImagePicker.Directory.Default)
                .Extension(ImagePicker.Extension.Jpg)
                .AllowOnlineImages(false)
                .Scale(600, 600)
                .AllowMultipleImages(true)
                .EnableDebuggingMode(false)
                .Build();
        }

        public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
#if DEBUG
            Log.Debug(
                MyTag,
                $"OnActivityResult() called with: requestCode = [{requestCode}], resultCode = [{resultCode}], data = [{data}]"
            );
#endif
            if (requestCode == ImagePicker.ImagePickerRequestCode && resultCode == Result.Ok)
            {
                // .ToList() available on "Net.Alhazmy13.MediaPicker" namespace
                _pathList = data.GetSerializableExtra(ImagePicker.ExtraImagePath).ToList();

                LoadImage();
            }
        }

        private void LoadImage()
        {
#if DEBUG
            Log.Debug(MyTag, $"LoadImage: {_pathList.Count}");
#endif
            _path.Text = (_pathList[0]);
            _imageView.SetImageBitmap(BitmapFactory.DecodeFile(_pathList[0]));
        }
    }
}

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.4.0 311 9/2/2018