Xamarin Forms Android从图像选择器意图获取文件扩展

时间:2018-09-28 22:08:21

标签: c# android xamarin.forms

是否可以从图像意图中获取文件扩展名或mime类型?

下面的代码输出:

  

文件   路径:content://com.android.providers.media.documents/document/image%3A78

    private void StartImagePicker()
    {
        var imageIntent = new Intent();
        imageIntent.SetType("image/*");
        imageIntent.SetAction(Intent.ActionGetContent);
        StartActivityForResult(
            Intent.CreateChooser(imageIntent, "Select photo"), 0);
    }
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (resultCode == Result.Ok && requestCode == 0)
        {
            print("File Path:" + data.DataString);
        }
    }

0 个答案:

没有答案