3

I'm trying to make an android app with a webview which can upload images to a html page. I think i found a solution here: Android ACTION_IMAGE_CAPTURE Intent but i'm having trouble translating everything to Xamarin c#, any can help me here? the code i'm interestet in is:

       File imageDirectory = new File("/sdcard/signifio");
       String path = imageDirectory.toString().toLowerCase();
       String name = imageDirectory.getName().toLowerCase();


        ContentValues values = new ContentValues(); 
        values.put(Media.TITLE, "Image"); 
        values.put(Images.Media.BUCKET_ID, path.hashCode());
        values.put(Images.Media.BUCKET_DISPLAY_NAME,name);

        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(Media.DESCRIPTION, "Image capture by camera");
       values.put("_data", "/sdcard/signifio/1111.jpg");
     uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
        Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); 

        i.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        startActivityForResult(i, 0); 

more specific it's what classes i have to import to find Media.TITLE, Images.Media.BUCKET_ID.... and so forth.

Community
  • 1
  • 1
pjensen68321
  • 521
  • 1
  • 5
  • 15

1 Answers1

4

Try Android.Provider.MediaStore

If they aren't in their you could use the actual strings instead, see the Android documentation

Here's the call to getContentResolver Xamarin style:

this.ContentResolver.Insert(Android.Provider.MediaStore.Images.Media.ExternalContentUri, values);

For the location of the file use:

Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");

There is a recipe for using a camera intent in the Xamarin documentation.

Martynnw
  • 10,625
  • 5
  • 28
  • 27
  • NICE... thanks. i couldn't find them, but i use the string instead. what about the getContentResolver().insert function, and Media.EXTERNAL_CONTENT_URI cant find them anywhere... – pjensen68321 Nov 16 '13 at 08:33
  • So... i got one more question. i'm trying to find a place to store an image which the camera has taken. it has to be a place where both my app and the camera app have acecs to. i was thinking about. Environment.getExternalStoragePublicDirectory but i do not know where to find that in xamarin, or another even better place to put it? :) can you help me again?. thanks... – pjensen68321 Nov 16 '13 at 12:35