我有一个主要活动,其中有一个按钮和图像视图控件。我可以将从设备存储中选择的图片显示到Imageview。但是当我尝试从Intent获取图像URI时会发生错误。从图像视图中选择从SD卡中的图像获取物理路径并上传到服务器
我的按钮单击事件代码
private void TakeAPicture (object sender, EventArgs eventArgs)
{
var imageIntent = new Intent();
imageIntent.SetType ("image/*");
imageIntent.SetAction (Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(imageIntent, "Select Image"),0);
}
OnActivityresult重写代码
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
if (resultCode == Result.Ok) {
Uri selectedImageUri = data.GetData();// code to get URI and I am stuck here
string selectedImagePath = ImageFilePath.getPath(context, selectedImageUri);
var imageView =
FindViewById<ImageView> (Resource.Id.imageView1);
UploadImage (selectedImagePath);
}
完整的错误文本
Error CS1061: 'Android.Content.Intent' does not contain a definition for 'GetData' and no extension method 'GetData' accepting a first argument of type 'Android.Content.Intent' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Capture)
为什么我得到这个错误。在Android意图中是否没有称为GetData()的方法,或者我是否缺少任何特定的库?
它的小'g'试试这个'data.getData()' –
仍然是一样的错误:-( – Binoy