Skip to content

Instantly share code, notes, and snippets.

View baileysh9's full-sized avatar

Scott Bailey baileysh9

View GitHub Profile
@baileysh9
baileysh9 / MainActivity.cs
Last active February 8, 2017 21:58
Xamarin Forms Responding to Deep Link on Android
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
@baileysh9
baileysh9 / MainActivity.cs
Last active February 8, 2017 21:52
Xamarin Forms Android Deep Linking
[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"
]
@baileysh9
baileysh9 / AppDelegate.cs
Last active November 12, 2020 10:17
Deep Linking iOS
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)
@baileysh9
baileysh9 / MainPage.cs
Last active January 12, 2017 20:11
Xamarin forms Messaging Center
//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));
});
});
@baileysh9
baileysh9 / MainPage.cs
Last active January 12, 2017 20:03
Button event for prompting for a photo to be added
//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")
{
@baileysh9
baileysh9 / MainActivity.cs
Last active January 12, 2017 19:52
Handling Bitmap rotation on background thread on Android
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;
@baileysh9
baileysh9 / MainActivity.cs
Last active January 12, 2017 19:39
Android receiving the call back from camera and gallery
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)
@baileysh9
baileysh9 / CameraAndroid.cs
Last active May 2, 2017 14:22
Android camera implementation
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
@baileysh9
baileysh9 / CameraIOS.cs
Last active January 12, 2017 19:19
iOS Launching the camera and getting a picture back
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)
{
@baileysh9
baileysh9 / CameraIOS.cs
Last active May 1, 2017 13:42
iOS Getting camera permission
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);