Ejemplo n.º 1
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.Main);
			
			Button videoButton = FindViewById<Button> (Resource.Id.takeVideoButton);
			videoButton.Click += delegate {
				// MediaPicker is the class used to invoke the
				// camera and gallery picker for selecting and
				// taking photos and videos
				var picker = new MediaPicker (this);

				// We can check to make sure the device has a camera
				// and supports dealing with video.
				if (!picker.IsCameraAvailable || !picker.VideosSupported) {
					ShowUnsupported();
					return;
				}
				
				// The GetTakeVideoUI method returns an Intent to start
				// the native camera app to record a video.
				Intent intent = picker.GetTakeVideoUI (new StoreVideoOptions {
					Name = "MyVideo",
					Directory = "MyVideos",
					DesiredLength = TimeSpan.FromSeconds (10)
				});

				StartActivityForResult (intent, 1);
			};
			
			Button photoButton = FindViewById<Button> (Resource.Id.takePhotoButton);
			photoButton.Click += delegate {
				var picker = new MediaPicker (this);

				if (!picker.IsCameraAvailable || !picker.PhotosSupported) {
					ShowUnsupported();
					return;
				}

				Intent intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions {
					Name = "test.jpg",
					Directory = "MediaPickerSample"
				});

				StartActivityForResult (intent, 2);
			};
			
			Button pickVideoButton = FindViewById<Button> (Resource.Id.pickVideoButton);
			pickVideoButton.Click += delegate {
				var picker = new MediaPicker (this);
				
				if (!picker.VideosSupported) {
					ShowUnsupported();
					return;
				}

				// The GetPickVideoUI() method returns an Intent to start
				// the native gallery app to select a video.
				Intent intent = picker.GetPickVideoUI();
				StartActivityForResult (intent, 1);
			};

			Button pickPhotoButton = FindViewById<Button> (Resource.Id.pickPhotoButton);
			pickPhotoButton.Click += delegate {
				var picker = new MediaPicker (this);

				if (!picker.PhotosSupported) {
					ShowUnsupported();
					return;
				}

				Intent intent = picker.GetPickPhotoUI(new StoreCameraMediaOptions {
					Name = "selected.jpg",
					Directory = "MediaPickerSample"
				});
				StartActivityForResult (intent, 2);
			};
		}