这里是我正在使用的代码,它运行得很好,但是如何仅将文件类型设置为jpg和png,并禁止/不显示图库中的其他任何图像?
private void ButtonOnClick(object sender, EventArgs eventArgs) {
Intent = new Intent();
Intent.SetType("image/*");
Intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), PickImageId);
}
#endregion
#region Get the Path of Selected Image
private string GetPathToImage(Uri uri) {
string path = null;
// The projection contains the columns we want to return in our query.
string[] projection = new[] {
Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data };
using (ICursor cursor = ManagedQuery(uri, projection, null, null, null)) {
if (cursor != null) {
int columnIndex = cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data);
cursor.MoveToFirst();
path = cursor.GetString(columnIndex);
}
}
return path;
}
#endregion
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
// For single image Selection
if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null)) {
Uri uri = data.Data;
_imageView.SetImageURI(uri);
path = GetPathToImage (uri);
}
}