Android applications in C# using Visual Studio
- Posted in:
- Android
- C#
- Mono
- MonoDroid
- Visual Studio
I recently got myself an Android mobile phone and was really interested in writing applications for it. After downloading the Android SDK as well as the 32-bit Java SDK (noooooo!) I got it all installed and running the sample apps with Eclipse and browsed around the code.
Firstly, I wasn’t really too keen on getting into another development environment. Secondly, I really didn’t want to do any Java development if I didn’t have to. C# is my happy place, C++ is for the ugly stuff if you need it, Java is just, well, ugly... Besides the last time I did any serious Java was in college, enter MonoDroid to save the day!
Getting Started
To get everything installed read this guide. Then you can read about the API and architecture to get a better understanding about how it all gels together. Pretty much everything you need including signing up for the newsletter can be found by going directly to www.monodroid.net.
Once you have everything installed it’s pretty easy to get going. The beauty about diving in using a language you are familiar with, means you can get used to the Android SDK without having any knowledge of Java or even C++ (for more advanced features). MonoDroid wraps up all the calls using standard .NET constructs through a JNI bridge, plus, you get all of the power of the standard .NET API’s which work in Linux/Android.
Hello Android
Following the tradition of “Hello World”, let’s jump right in and write an Android application.
- Make sure that you have everything installed, this guide couldn’t have made it easier.
- Create a new Project in Visual Studio:
- MonoDroid does most of the heavy lifting for you. If you’re familiar with Android projects in Eclipse you should have any problems with the structure. Android uses layout and string resource files (the right way) for the UI. Activities are like UI controllers, all the info you need is on the Android Developers website.
- Just run the application to check everything is working correctly, if you don’t have a device attached or an emulator running then now is the time to create one:
- If you don’t see anything then just click “Start emulator image”:
- Once again MonoDroid holds your hand by signing the package and also installing the Mono runtime if it’s not already available.
WARNING: If you are running an emulator then this will take a while, if you have a monster PC that does it in seconds then I hate you. - Unlock the phone/emulator and click the button:
That’s it! There is a lot of documentation on writing Android applications. Java isn't that far off in syntax to C# so it will be easy to pick up sample code all over the place.
More Information
The best place to start is the MonoDroid API design documentation. Do yourself a favour and browse the classes in the Android namespace. Make sure you check Android.Provider which gives you access to things like Contacts, Settings, Calls Logs etc. through static classes.
This Justin guy slicked the domain www.mono-droid.com in July 2010 already so this isn’t new, just widely available now and free for the time being. There is a lot of useful information on installing and developing here. He’s got videos too, everyone loves videos.
Comments
Hi, good stuff here, i was looking for info about making android app using delphi.
masdhaniPretty much everything needed to get started. Nice Article...Thank You
NileshLooks like it's not that difficult to get into Android development. I guess that is why the Android Market has so many apps. Thanks for the tutorial.
Droid X CasesWow..i did not knew that we can develop Android apps using C# itself. But looks like the IDE of Mono is a paid one. Is there any other such tool available for free?
SoanCan we use .net DLLs also with Mono For Android? I mean embedding them in the bin folder just like we do in normal web apps?
Soan[b]@Soan:[/b] MonoDroid is indeed a paid for product and rightfully so, it's very unique and build off Mono (free) bridge .NET on a seemingly unsupported platform. It is getting taken very seriously though and sponsored by Xamarin now providing professional support. I haven't seen a free product yet since you can already use Java or Native C++ to write Android applications, it's unlikely something like this will be free anytime soon.
WernerAll the same rules apply for Android (or rather applications executing on Mono) as they do in a Windows environment, web or desktop. Dependencies will always be searched for in the direct executing directory of the application, GAC, PATH and alternative configured probing paths. The idea behind Mono is to be able to deploy and run your application on a non-Windows platform without any significant changes. It even changes Windows path backslashes (\) to forward slashes (/) when running on Linux to maintain compatibility. As stated on the Mono site
[quote]An open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET[/quote]
means your app won't know if it's calling Mono framework assemblies, Microsoft .NET framework assemblies or your own custom built ones.
I love developing apps for Android but before coming through this post I have no idea that it is possible even with C# in Visual studio.you really gives me the thing I need most in my life.
RaheelMy life is now complete! :D
LynzWell, not exactly, but thanks for this awesome article! Gonna have tons of fun with this now.
Yeah, sadly, it IS paid.... and its price is about 999 € or $ (I forgot)
comradeI first thought it was bout 99, but noo, its a thousand bucks D:
It would be nice for a hobbiest version. But it is too pricy.
Fred BUtzThanks for your artical. It is good to know how to develop for that platform with .NET
HenryFor personal use you can buy the professional license, $400.
JurgenI was so excited to find this article. Then only to find out I am going to be forced to fork over some serious kizash. No thanks! Plz let us know up front before providing a link off site "To get everything installed" that we are going to be dinged to install.
TaersiousAt the time the article was written, MonoDroid was still open source and freely available. About three months later the project developers got canned and Novell bought them out. It was once again bought by Xamarin who decided to close the source and sell it some time after that.
WernerNow it's only available as a trial and I don't mean to dupe anyone into buying it. Here's an article of when it all happened if anyone is interested: conceptdev.blogspot.com/.../...marin-what-now.html
Thats it ! I finally found it. Thank you very much for the tutorial. I really was looking for articles that discuss the making android app. once again, thank you.
Dades93life is now complete! :D
idgamerWell, not exactly, but thanks for this awesome article! Gonna have tons of fun with this now.
Android SDK build in C language programing
AlanaThanks for your artical. It is good
imonbeethanks for info serrr
imonbeenice share bro
ngapak softwarei like your post about android application in visual studio :D
modigamesyou have good article and great work
Android Phone Applications