This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnCreate (Bundle bundle) | |
{ | |
base.OnCreate (bundle); | |
global::Xamarin.Forms.Forms.Init (this, bundle); | |
LoadApplication(new App()); | |
if (Intent != null && Intent.DataString != null) | |
{ | |
try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Activity (Label = "TestApp", Icon = "@drawable/icon", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] | |
[IntentFilter(new[] { Intent.ActionView }, | |
Categories = new[] { | |
Intent.ActionView, | |
Intent.CategoryDefault, | |
Intent.CategoryBrowsable | |
}, | |
DataScheme = "testAppForLinks" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) | |
{ | |
if(url != null) | |
{ | |
NSUrlComponents urlComponents = new NSUrlComponents(url, false); | |
string email = ""; | |
NSUrlQueryItem[] allItems = urlComponents.QueryItems; | |
foreach(NSUrlQueryItem item in allItems) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Whenever we send the byte array, we Sent the byte array with the string "ImageSelected", so we have to subscribe | |
//with the same format of a byte array and that string. | |
MessagingCenter.Subscribe<byte[]>(this, "ImageSelected", (args) => | |
{ | |
Device.BeginInvokeOnMainThread(() => | |
{ | |
//Set the source of the image view with the byte array | |
imageView.Source = ImageSource.FromStream(() => new MemoryStream((byte[])args)); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Button event for taking a photo | |
async void TakePhoto(object sender, EventArgs args) | |
{ | |
Device.BeginInvokeOnMainThread(async () => | |
{ | |
//Ask the user if they want to use the camera or pick from the gallery | |
var action = await DisplayActionSheet("Add Photo", "Cancel", null, "Choose Existing", "Take Photo"); | |
if (action == "Choose Existing") | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BitmapWorkerTask : AsyncTask<int, int, Bitmap> | |
{ | |
private Android.Net.Uri uriReference; | |
private int data = 0; | |
private ContentResolver resolver; | |
public BitmapWorkerTask(ContentResolver cr, Android.Net.Uri uri) | |
{ | |
uriReference = uri; | |
resolver = cr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) | |
{ | |
base.OnActivityResult(requestCode, resultCode, data); | |
//Since we set the request code to 1 for both the camera and photo gallery, that's what we need to check for | |
if(requestCode == 1) | |
{ | |
if (resultCode == Result.Ok) | |
{ | |
if (data.Data != null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Content; | |
using Android.Provider; | |
using Xamarin.Forms; | |
[assembly: Dependency(typeof(ImageTest.Droid.CameraAndroid))] | |
namespace ImageTest.Droid | |
{ | |
public class CameraAndroid : CameraInterface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void GotAccessToCamera() | |
{ | |
//Create an image picker object | |
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera }; | |
//Make sure we can find the top most view controller to launch the camera | |
var window = UIApplication.SharedApplication.KeyWindow; | |
var vc = window.RootViewController; | |
while (vc.PresentedViewController != null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void BringUpCamera() | |
{ | |
//Check if we have permission to use the camera | |
var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); | |
//If we don't have access, and have never asked before, prompt them | |
if (authorizationStatus != AVAuthorizationStatus.Authorized) | |
{ | |
var access = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); | |