public void CopyGuideFiles(LocalModule localModule) { if (Environment.ExternalStorageState.Equals(Environment.MediaMounted)) { string curPath = AppStorageManager.GetInstance(mContext).DefaultFolder; if (!AppFileUtil.NeedScopedStorageAdaptation()) { curPath = AppFileUtil.DefaultDocumentDirectory; Java.IO.File file = new Java.IO.File(curPath); if (!file.Exists()) { if (!file.Mkdirs()) { return; } } Java.IO.File sampleFile = new Java.IO.File(curPath + Java.IO.File.Separator + "Sample.pdf"); if (!sampleFile.Exists()) { localModule.CopyFileFromAssertsToTargetFile(sampleFile); } Java.IO.File guideFile = new Java.IO.File(curPath + Java.IO.File.Separator + "complete_pdf_viewer_guide_android.pdf"); if (!guideFile.Exists()) { localModule.CopyFileFromAssertsToTargetFile(guideFile); } } else if (!TextUtils.IsEmpty(curPath)) { Uri uri = AppFileUtil.ToDocumentUriFromPath(curPath); if (AppFileUtil.IsDocumentTreeUri(uri)) { DocumentFile directory = AppStorageManager.GetInstance(mContext).GetExistingDocumentFile(uri); if (directory == null) { return; } string fileName = "Sample.pdf"; DocumentFile file = directory.FindFile(fileName); if (file == null) { file = directory.CreateFile(AppFileUtil.GetMimeType(fileName), fileName); localModule.CopyFileFromAssertsToTargetFile(file); } fileName = "complete_pdf_viewer_guide_android.pdf"; file = directory.FindFile(fileName); if (file == null) { file = directory.CreateFile(AppFileUtil.GetMimeType(fileName), fileName); localModule.CopyFileFromAssertsToTargetFile(file); } } localModule.SetCurrentPath(curPath); } } }
public void OnFilePathChanged(string path) { if (AppFileUtil.NeedScopedStorageAdaptation()) { if (path == null || AppStorageManager.GetInstance(ApplicationContext).IsRootVolumePath(path)) { return; } AppFileUtil.CheckCallDocumentTreeUriPermission(this, REQUEST_OPEN_DOCUMENT_TREE, AppFileUtil.ToDocumentUriFromPath(path)); } }
private void UpdateLocalModule() { App app = App.Instance(); app.CopyGuideFiles(App.Instance().GetLocalModule(filter)); if (AppFileUtil.NeedScopedStorageAdaptation()) { app.GetLocalModule(filter).SetCurrentPath(AppStorageManager.GetInstance(ApplicationContext).DefaultFolder); } app.GetLocalModule(filter).UpdateStoragePermissionGranted(); }
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); }