コード例 #1
0
        protected bool ChooseFile(IValueCallback filePathCallback, Intent intent, string title)
        {
            if (_activity == null)
            {
                return(false);
            }

            void callback(Result resultCode, Intent intentData)
            {
                if (filePathCallback == null)
                {
                    return;
                }

                var result = ParseResult(resultCode, intentData);

                filePathCallback.OnReceiveValue(result);
            }

            _requestCodes ??= new List <int>();

            var newRequestCode = ActivityResultCallbackRegistryHelper.RegisterActivityResultCallback(callback);

            _requestCodes.Add(newRequestCode);

#pragma warning disable CA2000 // Dispose objects before losing scope
            _activity.StartActivityForResult(Intent.CreateChooser(intent, title), newRequestCode);
#pragma warning restore CA2000 // Dispose objects before losing scope

            return(true);
        }
コード例 #2
0
        public void UnregisterCallbacks()
        {
            if (_requestCodes == null || _requestCodes.Count == 0 || _activity == null)
            {
                return;
            }

            foreach (var requestCode in _requestCodes)
            {
                ActivityResultCallbackRegistryHelper.UnregisterActivityResultCallback(requestCode);
            }

            _requestCodes = null;
        }