protected override Task <StorageFolder> GetRootFolderAsync()
        {
            var localCache   = ApplicationData.Current.LocalCacheFolder.Path;
            var directory    = new File(localCache);
            var documentFile = DocumentFile.FromFile(directory);
            var rootFolder   = StorageFolder.GetFromSafDocument(documentFile);

            return(Task.FromResult(rootFolder));
        }
Exemple #2
0
 private DocumentFile GetDocumentFile(string path)
 {
     if (path.Contains("://"))
     {
         return(DocumentFile.FromTreeUri(context, Android.Net.Uri.Parse(path)));
     }
     else
     {
         return(DocumentFile.FromFile(new Java.IO.File(path)));
     }
 }
Exemple #3
0
        private void FinishWithResult(string documentId)
        {
            //var uri = DocumentsContract.BuildDocumentUri(Authority, documentId);
            var file   = _documentsProvider.GetFileForDocumentId(documentId);
            var uri    = DocumentFile.FromFile(file).Uri;
            var intent = new Intent();

            intent.SetData(uri);
            SetResult(Result.Ok, intent);
            Finish();
        }
        protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
        {
            switch ((ActivityRequest)requestCode)
            {
            case ActivityRequest.RequestDevelopmentSettings:
                UpdateDisplay();
                break;

            case ActivityRequest.RequestOpenDocumentTreeToApp:
                if (data != null && resultCode == Android.App.Result.Ok)
                {
                    Android.Net.Uri treeUri = data.Data;
                    if (treeUri != null)
                    {
                        _instanceData.CopyToAppSrcUri = treeUri.ToString();
                        if (!string.IsNullOrEmpty(_instanceData.CopyToAppSrcUri))
                        {
                            SelectCopyAppDir(false);
                        }
                    }
                }
                break;

            case ActivityRequest.RequestOpenDocumentTreeFromApp:
                if (data != null && resultCode == Android.App.Result.Ok)
                {
                    Android.Net.Uri treeUri = data.Data;
                    if (treeUri != null)
                    {
                        _instanceData.CopyFromAppDstUri = treeUri.ToString();
                        if (!string.IsNullOrEmpty(_instanceData.CopyFromAppSrcPath) && !string.IsNullOrEmpty(_instanceData.CopyFromAppDstUri))
                        {
                            try
                            {
                                DocumentFile srcDir = DocumentFile.FromFile(new Java.IO.File(_instanceData.CopyFromAppSrcPath));
                                DocumentFile dstDir = DocumentFile.FromTreeUri(this, Android.Net.Uri.Parse(_instanceData.CopyFromAppDstUri));
                                if (_activityCommon.RequestCopyDocumentsThread(srcDir, dstDir, (result, aborted) => { }))
                                {
                                    ActivityCommon.CopyFromAppSrc = _instanceData.CopyFromAppSrcPath;
                                    ActivityCommon.CopyFromAppDst = _instanceData.CopyFromAppDstUri;
                                }
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                }
                break;

            case ActivityRequest.RequestSelDirToApp:
                if (data != null && resultCode == Android.App.Result.Ok)
                {
                    _instanceData.CopyToAppDstPath = data.Extras?.GetString(FilePickerActivity.ExtraFileName);
                    if (!string.IsNullOrEmpty(_instanceData.CopyToAppSrcUri) && !string.IsNullOrEmpty(_instanceData.CopyToAppDstPath))
                    {
                        try
                        {
                            DocumentFile srcDir = DocumentFile.FromTreeUri(this, Android.Net.Uri.Parse(_instanceData.CopyToAppSrcUri));
                            DocumentFile dstDir = DocumentFile.FromFile(new Java.IO.File(_instanceData.CopyToAppDstPath));
                            if (_activityCommon.RequestCopyDocumentsThread(srcDir, dstDir, (result, aborted) => { }))
                            {
                                ActivityCommon.CopyToAppDst   = _instanceData.CopyToAppDstPath;
                                ActivityCommon.CopyFromAppDst = _instanceData.CopyFromAppDstUri;
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
                break;

            case ActivityRequest.RequestSelDirFromApp:
                if (data != null && resultCode == Android.App.Result.Ok)
                {
                    _instanceData.CopyFromAppSrcPath = data.Extras?.GetString(FilePickerActivity.ExtraFileName);
                    if (!string.IsNullOrEmpty(_instanceData.CopyFromAppSrcPath))
                    {
                        SelectCopyDocumentTree(true);
                    }
                }
                break;

            case ActivityRequest.RequestSelDirDelApp:
                if (data != null && resultCode == Android.App.Result.Ok)
                {
                    string delPath = data.Extras?.GetString(FilePickerActivity.ExtraFileName);
                    if (!string.IsNullOrEmpty(delPath))
                    {
                        try
                        {
                            DocumentFile delDir = DocumentFile.FromFile(new Java.IO.File(delPath));
                            _activityCommon.RequestDeleteDocumentsThread(delDir, (result, aborted) => { });
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
                break;
            }
        }