所以我添加了在我的应用上上传个人资料图片的选项。但是当用户尝试上传个人资料图片时,只有相机显示。不显示画廊(下面是我使用的代码)
public void OpenIntentImageGallery(string title, bool allowMultiple, bool imageCropping = true)
{
try
{
if (!MSTools.CheckAllowedFileUpload())
{
Methods.DialogPopup.InvokeAndShowDialog(Context, Context.GetText(Resource.String.Lbl_Security), Context.GetText(Resource.String.Lbl_Error_AllowedFileUpload), Context.GetText(Resource.String.Lbl_Ok));
return;
}
Methods.Path.Chack_MyFolder();
Intent intent = (int)Build.VERSION.SdkInt switch
{
<= 25 => new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri),
_ => Android.OS.Environment.GetExternalStorageState(null)!.Equals(Android.OS.Environment
.MediaMounted)
? new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri)
: new Intent(Intent.ActionPick, MediaStore.Images.Media.InternalContentUri)
};
intent.SetType("image/*");
intent.PutExtra("return-data", true); //added snippet
switch (Build.VERSION.SdkInt)
{
case > BuildVersionCodes.Q:
intent.SetAction(Intent.ActionGetContent);
break;
}
if (imageCropping && Build.Manufacturer!.ToLower() == "samsung")
{
intent.PutExtra("crop", "true");
var myUri = Uri.FromFile(new File(Methods.Path.FolderDcimImage, Methods.GetTimestamp(DateTime.Now) + ".jpeg"));
intent.PutExtra(MediaStore.ExtraOutput, myUri);
//intent.PutExtra("outputFormat", Bitmap.CompressFormat.Jpeg.ToString());
}
switch (allowMultiple)
{
case true:
intent.PutExtra(Intent.ExtraAllowMultiple, true);
break;
}
if (intent.ResolveActivity(Context.PackageManager) != null)
Context.StartActivityForResult(Intent.CreateChooser(intent, title), 500);
}
catch (Exception e)
{
Methods.DisplayReportResultTrack(e);
}
}