如何使我的应用程序的特定文件夹出现在图库中?

How to make a specific folder of my application appear in gallery?

我有这段代码正确存储在我手机的内部存储器中,在应用程序的文件夹中创建了一个名为 "credentials" 的文件夹,我如何在图库中注册该文件夹?

private void ObtenerCaptura() {
            try {
                String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").Format(new Java.Util.Date());
                string folder = GetExternalFilesDir("credenciales").ToString();
                string folderFile = System.IO.Path.Combine(folder, timeStamp + ".jpg");
                var fos = new FileStream(folderFile, FileMode.CreateNew);
                bitmapCorte.Compress(Bitmap.CompressFormat.Jpeg, 100, fos);
                fos.Close();
                Toast.MakeText(this, "Captura guardada.", ToastLength.Short).Show();
            }
            catch (Exception e) {
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Funciones Android");
                alert.SetMessage("Ha ocurrido un error al cargar la captura.");
                alert.SetPositiveButton("Ok", (senders, args) =>
                {
                    //
                });
                Dialog dialog = alert.Create();
                dialog.Window.SetType(WindowManagerTypes.SystemAlert);
                dialog.Show();
                Log.Info(typeof(PolylineTask).Name, "Error al crear FileStream en ObtenerCaptura");
                Log.Error(typeof(PolylineTask).Name, e.Message);
            }
        }

我已经创建了一个新的应用程序来测试这个问题,并且可以使用以下方法:

MediaStore.Images.Media.InsertImage(this.ContentResolver, myBitmap, "SocialPhoto", "testing");

注:

1.you需要获取图片的Bitmap格式;

2.you需要在AndroidManifest文件中添加权限,在AndroidM及以上添加Runtime Permisssion。

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />