Android

Xamarin: how to set up an Android device for Debugging

Xamarin comes with some emulators for development of an Android app. While these emulators are working and are also available in all supported screen sizes, the performance of them is really bad.

That’s why I chose debugging via device, which is a lot faster than the emulators once you have the required Xamarin extensions installed.

Here is how to set up an Android device for debugging. First thing you need to know is which OS version is running. On most Android devices, you will find this information under Settings/About (or Info)/Software information. If you don’t have the result there, you should check the manual where to find this information on your device.

Screenshot_2013-12-29-07-03-31

Activate Debugging until Android 3.2

  • go to Settings from your Application Menu
  • choose Applications
  • open the Development item
  • you will see now the option to activate USB debugging:

Android_debug_until_32

Activate Debugging on Android 4.0, 4.1

  • go to the Settings Menu
  • choose Developer options and activate USB debugging:

Android_debug_until_32

Activate Debugging on Android 4.2 and higher

  • go to the Settings Menu
  • select About
  • tap the Build Number 7 times (after the 4th tap a notification will appear that counts down the required taps)

Screenshot_2013-12-29-07-04-36

 

Installing drivers

Now our devices are ready to be connected to our PC, where we need to install the corresponding USB drivers. Normally you just need to plug in your Android device, Windows will search for the right driver and install it for you. If you want to install the driver manually, here is a list of OEM driver packages: http://developer.android.com/tools/extras/oem-usb.html#Drivers

Deploying an App for debugging

After the drivers have been installed, your device should now be recognized by Windows and also by Xamarin Studio.

Using our gettingstarted project from my first blog post, you should have now two options to deploy the application to your device:

Run With…

Screenshot (273)

Just hit ‘Debug’…

Screenshot (275)

Xamarin Studio installs now the required packages for debugging, and after that, you will be able to debug you application.

Speeding up re-deployments

Xamarin will install all developing packages including your app from scratch every time you deploy the app. To speed things up, there is an option to speed things a little up.

To activate/check if this option is already activated, click on the ‘options’ button of your project and select ‘Options’ in the context menu:

Screenshot (276)

Select ‘Android Build’ and activate these two options:

Screenshot (276)

 

This way, Xamarin will deploy only changes that have been made to your code, while keeping the required packages on your device. Xamarin Studio will detect if an update to those packages is required.

However, sometimes you will need to clean your solution and do a complete re-deploy (like you are doing with a Windows Phone project sometimes, too).

In very seldom cases (happened 3 times to me by now), you will need to uninstall your app and all of the Xamarin packages from your device. To do so, go to Settings/Apps on your device. In the application list, you will find some apps that start with ‘Mono’:

Screenshot_2013-12-29-07-57-13

To uninstall them, tap the items and select ‘Uninstall’ in the App info screen:

Screenshot_2013-12-29-07-58-43

 

Xamarin Studio will now re-deploy all required packages to your device, and your app should run again for debugging.

Like always, I hope this post is helpful for some of you.

Happy coding!

Posted by msicc in Android, Dev Stories, Xamarin, 2 comments

New Series: developing for Android with Xamarin

xamandroid

Prolog

In the last few month I was developing not only my personal projects, but also on my daily 9to5 job. I am working on an internal app that will help to improve the customer experience amongst the customers of my employer Telefónica.

The project has a simple setup in phase I, with collecting data and sending them via mail. The challenge for me was how to get the Windows Phone app (yes, Windows Phone was first!) to Android.

I knew it would take some time to get started with Android development, and was searching for possible solutions to speed things up. I knew from Xamarin already, and was able to obtain a 1-year license for Android (maybe iOS will follow later).

Some of my fellow WinPhans and WinPhanDevs will scream out very loud at the moment. I understand that. But honestly, I could not let go away this huge opportunity for me – as it touches both my daily job and my private developer story. To calm you down: I will always love Windows Phone and Windows and develop for it first. I will always remain a WinPhanDev. But I need to go forward, and this is a big step.

Let’s go back to the topic.

With this blog post, I am kicking off a new blogging series for Android development with Xamarin. The huge advantage of using Xamarin is that I am able to use my C# knowledge to develop apps for other platforms – which makes it a little easier to get things done.

However, if you start with another platform, you still have to learn the platform structure. Without knowing or be willing to learn it, you will be lost very fast. Every OS has its own specific UI rules, save handling and so on. This is what I will blog about.

The Windows Phone app I ported to Android has a item Pivot, which I ported over to Android. It has a little different appearance, but it works in a similar way with tapping the header or a swiping gesture to move between the items/pages.

To get there, I had to learn a lot about Android – and I will share it all with you out there.

My series will cover the following topics:

Installing Xamarin

Installing Xamarin is pretty easy – but will take some time. Click on this link to download the Xamarin IDE. The IDE will ask you for which platform you want to develop for (let’s choose only Android for the moment) and then download a huge amount of additional SDKs like the Java and the Android SDK (Android apps are Java based, if you didn’t knew).

Screenshot (267)

On the screenshot above you can see the starting page of Xamarin Studio. On the left side you have the list of recent solutions, in the middle you see Xamarin news and finally the pre-built apps section.

Xamarin Studio has a lot together with Visual Studio, and you also can take a lot of settings to adjust the appearance for your needs. Let’s start a new project by clicking on the ‘New’ button

Screenshot (270)

Xamarin will set up a .sln file with everything we need for the moment. After creating the project has been created, you’ll see these lines of code:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace gettingstarted
{
	[Activity (Label = "gettingstarted", MainLauncher = true)]
	public class MainActivity : Activity
	{
		int count = 1;

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.myButton);

			button.Click += delegate {
				button.Text = string.Format ("{0} clicks!", count++);
			};
		}
	}
}

 

These few lines should help to get started with the basic structure of an Android App.

Android has Activities. Activities can be seen as the code behind files in a C# project. Here begins all the action of an Android app. Xamarin automatically ads the Label (project name) and in this case, also the MainLauncher property, which will run this code on app start up.

To get something displayed in our app, we need to load a Layout or create the view from the code. This is what the SetContentView() method is about. Without this, the app will compile but displays nothing. In this demo app, a basic layout with a button inside is created:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
</LinearLayout>

 

We already have the first difference to other C# projects here. In order to make the button visible for our code in the Activity, we need to search our resources for the button. This is done by the FindViewById<T>() method. As soon as it is visible to our code, we are able to create a delegate for our button Click event.

The button counts then the clicks on it and changes the text based on the number of clicks.

To understand more about the structure of an Android App, I highly recommend to read the documentation. For me, especially these links were helpful:

There are some more resources that are helpful, but for getting started those four links should be enough. I will cover some of the topics above also with my upcoming posts and link additional resources as well.

As with the Windows Phone development, also StackOverflow is a big help as well as the Xamarin  Android forums.

Until the next post, happy coding!

Posted by msicc in Android, Dev Stories, Xamarin, 0 comments

Tap+Send: The Love Story of 2 NFC Devices

NFC1

Innovation in technology is hit and miss for a number of reasons. To prognosticate what advances in technology will be accepted by the general public is by no means, an exact science. There’s a constant barrage of new expensive toys with exclusive features that are “sure” to turn the world upside down, only to hit the market and fade into oblivion as a “niche market” concept. There are more than a handful of these types of advancements in the devices we all use on a day-to-day basis now, regardless of preferred OS. Yet for all intent and purpose, most don’t get utilized because of a lack of end users with similar features. NFC is one of those exclusive features and having 2 devices with it, I’ll explain why I see this being a feature that is here to stay.

nokia-speakers

I won’t spend much time explaining NFC as most of you know about it. Quickly, NFC(near field communication) is a set of standards for devices to establish radio communication with each other by touching them together or bringing them into close proximity. Up to this point, most of the NFC ado has been made about NFC tags and the Qi wireless charging capabilities with our Windows Phone 8’s: Charging plates, charging stands, phone covers with Qi, the JBL PowerUp speaker that can charge your device while playing. Being such a new innovation in smartphones, there are limited accessories to aid in this new technology, even HTC used JBL’s speaker for Nokia to advertise its most recent Android device. In addition to the lack of accessories currently available for NFC enabled devices, there are a lack of end users who actually own a NFC enabled device. NFC is about sharing and if you have no one to share with, it becomes one of those “niche market” features fading into the past, full potential never being realized.

tap-send-wp8

My wife and I both have Nokia Lumia 920’s which has led to a unique experience among smartphone users, being able to utilize many aspects of the NFC’s features and that is what I’ll focus on now. One of the drawbacks to WP7 was the inability to share via Bluetooth. This was remedied in Windows Phone 8 allowing for the next evolutionary stage is sharing photos, videos, songs, documents, contacts, or websites…via NFC. No more waiting while you tried to get your Bluetooth to find the other incompatible device right next to you, no more waiting for the other person to email you with that important file or pic even though they’re standing next to you, no more waiting for file to download when opening your email, no…things have changed. Tap your phone and give or get that info now in a fun and engaging manner! I am beginning to see the Tap and Share feature as perhaps the most innovative feature with the largest amount of potential to the end-user. Of course like most new technologies this is assuming it can make it onto enough devices and into enough hands, driving the hardware cost down and finding its way onto lower cost devices for the masses to use. Without “the masses”, NFC, aside from wireless charging, losses its luster. In some sense, I’m actually rooting for HTC and Samsung to have some success with their Android devices utilizing NFC, the better they do, the better results all OS’s with this feature will do. Again, NFC’s success really does rely upon the masses.

Share1

My wife and I use the Tap+Send feature frequently. We’re constantly sharing pictures and with Tap+Send, it’s always much faster and a sure bet the recipient gets the file! I’ve found that we’re both more likely to share pics when it’s as simple as Tap+Send. Send 1 or send multiple, it doesn’t matter. Honestly, I’m finding myself impatient now when I know someone is sending me a file and I have to wait for it to arrive in my inbox and still have to download it! Another added benefit to sharing your pics or videos via NFC is the data aspect. I avoid having to use up my allotted data both with my carrier and at home on WiFi, for those of you with shared family plans or have data limits because of satellite internet, you understand.

App

A close 2nd in utilization when it comes to Tap+Send: App Sharing, we do this at least once a day! As many of you know sharing apps via your WP8 was made easier by Microsoft when they gave us the ability to share it directly from the app side of your device. By pressing and holding an app, “Share” is now listed as on option and even better…you can do it via Tap+Send! Lightning fast access to the app’s direct link in the Windows Phone Store! Again, no waiting for it to show up in your inbox, it’s just there! I actually transferred all my apps this way when switching over from my old 920 to my new 920 to see how arduous it was. I’ve used App Reinstaller and it can take quite a long time to auto-populate your entire app history. I was blown away at how fast I was able to get my new 920 up and running with all my old apps!

sharing

We also share music via Tap+Send. I’m going to start by saying that neither of us has a music pass of any sort. When we see something we like we purchase it, so I’m not sure how sharing music on a pass will work. My experience with music and Tap+Share has been sending and receiving music from my computer or music purchased from Zune and Xbox Music, all which has transferred and played without a hitch! It’s a relatively quick process, taking about 30 seconds from share to play!

Contacts1

My wife and I have busy schedules between our marriage, kids, friends, activities, and work. We have many people who are friends in common and some aren’t for one reason or another, thus our people hubs are similar but not an exact match. There are many apps that help share contacts and WP does a pretty good job at giving you ways to share contacts as well, however none come close to the efficiency and speed with which you can do it when shared using Tap+Share! 2 taps and a phone “high-five” and the info is waiting to be saved.

Ready-for-enterprise

The last way I’ll look at is actually tied into the “Gold Mine” Microsoft sees in enterprise, sharing your documents via Tap+Send. The ways I’ve talked about using Tap+Send have been for the average user, but we all know that Microsoft is targeting businesses globally with WP8. The ability to share documents as simply as touching phones can be a game changer. Running late and can’t wait for that file to get to your inbox…need it now…phone “high five” and off you go! Not a gimmick, time is money and that makes dollars and sense!

I hope in time that we’ll see more and more devices showing up on the market NFC enabled at every level of phone: high, mid, and low range. This will take time but it’s time well worth it. When I stop and think back 2 years ago, I think about my Windows Mobile HTC Touch Pro 2, it could share via Bluetooth but it was a disaster of a process to get it to pair or be paired with not to mention the inability to retrieve most of the files types being sent! Our beloved Windows Phone has come a million miles from its predecessor, not without bumps in the road. Without those bumps though, many would forget all the amazing feats accomplished and adversity Microsoft/Windows Phone has managed to overcome!

Posted by TheWinPhan in Archive, 1 comment