示例#1
0
 public void SelectDefaultFolderOrNot(Activity activity)
 {
     if (AppFileUtil.NeedScopedStorageAdaptation())
     {
         if (activity != null && TextUtils.IsEmpty(AppStorageManager.GetInstance(activity).DefaultFolder))
         {
             AppFileUtil.CheckCallDocumentTreeUriPermission(activity, MainActivity.REQUEST_SELECT_DEFAULT_FOLDER,
                                                            Uri.Parse(AppFileUtil.ExternalRootDocumentTreeUriPath));
             UIToast.GetInstance(activity).Show("Please select the default folder,you can create one when it not exists.");
         }
     }
 }
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == REQUEST_EXTERNAL_STORAGE_MANAGER)
            {
                AppFileUtil.UpdateIsExternalStorageManager();
                if (!AppFileUtil.IsExternalStorageManager)
                {
                    CheckStorageState();
                }
                UpdateLocalModule();
            }
            else if (resultCode == Result.Ok)
            {
                if (requestCode == AppStorageManager.OpenTreeRequestCode || requestCode == REQUEST_SELECT_DEFAULT_FOLDER)
                {
                    if (data == null || data.Data == null)
                    {
                        return;
                    }

                    Uri           uri       = data.Data;
                    ActivityFlags modeFlags = data.Flags & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission);
                    ContentResolver.TakePersistableUriPermission(uri, modeFlags);
                    LocalModule       localModule    = App.Instance().GetLocalModule(filter);
                    AppStorageManager storageManager = AppStorageManager.GetInstance(ApplicationContext);
                    if (TextUtils.IsEmpty(storageManager.DefaultFolder))
                    {
                        string defaultPath = AppFileUtil.ToPathFromDocumentTreeUri(uri);
                        storageManager.DefaultFolder = defaultPath;
                        App.Instance().CopyGuideFiles(localModule);
                        localModule.SetCurrentPath(defaultPath);
                    }
                    else
                    {
                        localModule.ReloadCurrentFilePath();
                    }
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(Android.Views.WindowFeatures.NoTitle);
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            AppTheme.SetThemeFullScreen(this);
            AppTheme.SetThemeNeedMenuKey(this);
            ActManager.Instance.CurrentActivity = this;

            mLicenseValid = App.Instance().CheckLicense();
            if (!mLicenseValid)
            {
                return;
            }

            if (this.Intent != null && this.Intent.Action != null)
            {
                filter = Intent.Action;
            }

            if (Build.VERSION.SdkInt > BuildVersionCodes.Q && !AppFileUtil.IsExternalStorageLegacy)
            {
                AppStorageManager storageManager = AppStorageManager.GetInstance(this);
                bool needPermission = storageManager.NeedManageExternalStoragePermission();
                if (!AppStorageManager.IsExternalStorageManager && needPermission)
                {
                    storageManager.RequestExternalStorageManager(this, REQUEST_EXTERNAL_STORAGE_MANAGER);
                }
                else if (!needPermission)
                {
                    CheckStorageState();
                }
            }
            else if (Build.VERSION.SdkInt > BuildVersionCodes.M)
            {
                CheckStorageState();
            }

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.N)
            {
                StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
                StrictMode.SetVmPolicy(builder.Build());
            }

            AppStorageManager.OpenTreeRequestCode = REQUEST_OPEN_DOCUMENT_TREE;
            LocalModule local = App.Instance().GetLocalModule(filter);

            local.SetAttachedActivity(this);
            App.Instance().CopyGuideFiles(local);
            local.SetFileItemEventListener(this);
            local.SetCompareListener(this);
            local.SetOnFilePathChangeListener(this);

            View      view   = local.GetContentView(this.ApplicationContext);
            ViewGroup parent = (ViewGroup)view.Parent;

            if (parent != null)
            {
                parent.RemoveView(view);
            }
            SetContentView(view);

            HandleIntent(this.Intent);
        }