Hello,

For browsing for a picture in the gallery I use code like this:

            Intent browseFile = new Intent(Intent.ActionGetContent);
            browseFile.SetType("image/*");
            browseFile.AddCategory(Intent.CategoryOpenable);
            StartActivityForResult(browseFile,
(int)ActivityRequestCodes.SELECT_PHOTO);

To get the selected photo you override the OnActivityResult method in the
parent activity:

        protected override void OnActivityResult(int requestCode, Result
resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            switch (requestCode)
            {
                case (int)ActivityRequestCodes.SELECT_PHOTO:
                    if (resultCode == Result.Ok)
                    {
                        Android.Net.Uri selectedURI = data.Data;
                                // at this stage you have a URI for the
selected image and, in most cases, you can work directly with that
                                // and you don't need to know what the file
path and name are
                    }
                    break;

                .....
        }

If for some reason you do need to work with the actual file path and name
then you need a function like:

        public String getRealPathFromURI(Android.Net.Uri contentUri)
        {
            String[] projection = new String[] {
a.Provider.MediaStore.MediaColumnsConsts.Data };
            ContentResolver cr = this.ContentResolver;
            a.Database.ICursor cursor = cr.Query(contentUri, projection,
null, null, null);
            if (cursor != null && cursor.Count > 0)
            {
                cursor.MoveToFirst();
                int index =
cursor.GetColumnIndex(a.Provider.MediaStore.MediaColumnsConsts.Data);
                return cursor.GetString(index);
            }
            return null;
        }

The general idea with Android seems to be that you use the ContentProviders
and Uris to work with content, and you don't really need to worry about
where the actual files are. 

Hope this helps. The code is cut, pasted and hacked around with so it might
not make 100% sense.

Cheers,

Andy

-----Original Message-----
From: monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of jnmahi
Sent: 27 May 2011 12:15
To: monodroid@lists.ximian.com
Subject: Re: [mono-android] Reading and loading file from Gallery

Can anyone tell me how to access files in /mnt/sdcard or files in /data/data
???

--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/Reading-and-loading-file-from-
Gallery-tp4431195p4431541.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to