translate android java to xamarin c#
Question
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.
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow