Using Hyper-V and Visual Studio with Android x86 KitKat v4.4

Androidx86 is a project hosted on http://www.android-x86.org/. The purpose of the project is porting Android open source project to x86 platform, formerly known as “patch hosting for android x86 support“. The original plan is to host different patches for android x86 support from open source community.

Developers can actually use Hyper-V hosted Android x86 for testing and app development. Hyper-V is built into Windows 8.x and works much faster than Android emulators. In this walkthrough which requires about 10-15 minutes we’ll set up Android x86 in Hyper-V and deploy a Visual Studio Xamarin app to the virtual machine.

Overview

1. Deploy Android x86 in Hyper-V (3 minutes)
2. Deploy your APK from ADB or Visual Studio

Setting up Android x86 on HyperV

Installing Android x86 on Hyper-V is very easy: you create a VM, download Android x86 ISO from http://www.android-x86.org/download and install Android in your VM, like a regular Linux distribution. I used the latest KitKat version: android-x86-4.4-r1-iso Below are step-by-step instructions.

clip_image002

1. Start Hyper-V manager (in Windows 8.x Window-Q Hyper V), then create a new VM in Hyper-V Manager (New / Virtual Machine…)
clip_image004

2. Download Android x86 ISO from http://www.android-x86.org/download

3. Attach ISO to your VM (Media/DVD Drive/Insert Disk…) and select Android x86 ISO

4. Set up Android as you would a Linux distribution: it’ll prompt you to create and format a partition, install GRUB boot loader etc.

clip_image006

clip_image008

clip_image010

clip_image012

5. After the installation, Android x86 runs in your VM. You can now eject the ISO and let the Android boot.

Developing apps using Android x86 in Hyper-V

Android x86 running in Hyper-V is no different from any other Android device or emulator for ADB or Visual Studio. First we need to unlock Android x86 instance for development, then connect our Windows PC to it.

1. In Android x86 press Alt-F1 for command prompt, then type netcfg, which will give you an IP, e.g. 192.168.1.10, press Alt-F7 to go back to graphics shell

2. In Windows PC start ADB command prompt (provided with Android SDK) and type:

adb connect 192.168.1.10

3. If you use Visual Studio for development, for example for Xamarin apps, you can now select Android x86 virtual machine running in Hyper-V

clip_image013

4. Now you can deploy your APK from any file with adb install… or from Visual Studio directly to Android x86 emulator in Hyper-V.

Push Notifications for Xamarin.iOS

Configuring Notification Hubs for Xamarin.iOS apps

Some user devices are iOS-based, some Android, some Windows Phone, and the list goes on. Each of the native platforms has its own push notification framework and backend service. Azure Mobile Services allows the developer to configure a single Notification Hub (based on Microsoft Azure Service Bus Notification Hubs) through which notifications may be sent. The notification goes to each user via the correct push service according to her device’s requirements. Broadcast to millions in consumer scenarios, to tagged groups, to individuals with the same ease.

To use notifications hub from Azure Mobile Services with your iOS apps, you need to generate a certificate, register your iOS app for push notifications, save your certificate to a file and upload to Azure Mobile Services Management Portal, into your Notifications Hub. The whole process of generating a certificate, and configuring Azure Notification Hubs for use with iOS apps here, which is fairly extensive and has some screenshots.

Code snippet: Xamarin.iOS app using Push Notification Hubs

We use Xamarin Forms for best cross-platform portability: we can re-use the same UI and most of the middle tier in our Android project as well.

1. In Xamarin Studio on your Mac, or Visual Studio on your PC, create a new Xamarin Forms project. We will need to use WindowsAzure.Messaging from GitHub. Compile WindowsAzure.Messaging.dll and reference it in your project. This assembly provides iOS bindings for Notification Hub:

clip_image002

2. For Xamarin.iOS project, we need to make some changes in the AppDelegate.cs file. First, start by adding:
SBNotificationHub _hub;

public const string _azureConnection = “<Azure connection string>”;

public const string _notificationHubPath = “<Azure hub path>”;

3. Next in FinishedLaunching method add this to register for remote notifications in your app (providing several types of notifications):

UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(

UIRemoteNotificationType.Alert |

UIRemoteNotificationType.Badge);

4. Add the following methods to handle registration and notification processing.

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)

{

_hub = new SBNotificationHub(_azureConnection, _notificationHubPath);

_hub.UnregisterAllAsync (deviceToken, (error) => {

if (error == null)

{

NSSet tags = null; // create tags if you want

_hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>

{

// handle errors here

});

}

else

{

// handle errors here

}

});

}

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary options)

{

if (null != options && options.ContainsKey(new NSString(“aps”)))

{

NSDictionary aps = options.ObjectForKey(new NSString(“aps”)) as NSDictionary;

string alert = string.Empty;

if (aps.ContainsKey(new NSString(“alert”)))

alert = (aps[new NSString(“alert”)] as NSString).ToString();

if (!string.IsNullOrEmpty(alert))

{

UIAlertView avAlert = new UIAlertView(“Notification”, alert, null, “OK”, null);

avAlert.Show();

}

}

}

We can now register for hub notifications and receive notifications, displaying alerts in our Xamarin.iOS apps.

Reference:

Get started with Notification Hubs with Xamarin.iOS
Xamarin.iOS: Push Notifications in iOS