Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Tuesday, 3 May 2016

Building Android Applications using C#

Building Android Applications using C#

MonoDroid is a software product developed by Novell to build Android based mobile applications using C# and .NET. To install and work with MonoDroid, you need Visual Studio 2010. MonoDroid works as an add-on of Visual Studio 2010. Once installed successfully, the MonoDroid project templates are available in Visual Studio 2010. MonoDroid does not work with Visual Studio Express.

In this tutorial, we will learn how to build our very first Android based application using MonoDroid and Visual Studio 2010.

Installing MonoDroid

You can download the latest version of the MonoDroid from www.monodroid.net and follow the installation instructions here: http://monodroid.net/Installation

Once you have successfully installed the Android SDK, MonoDroid and all required software, you are all set to build your very first Android based application using C# and .NET.

Hello Android!

We are going to build our very first Android based application. In this application, we will display the Hello Android text on the screen.

Open Visual Studio 2010 and create a new project. Select Visual C# as the language, MonoDroid as the category in the left side bar list of the project template categories. See Figure 1.

Once you select the MonoDroid category, you will see the following three templates.

  • MonoDroid Application

  • OpenGL MonoDroid Application

  • MonoDroid Class Library

In this topic, we will use the MonoDroid Application project type. I will discuss OpenGL and Class Library project types later in this chapter.

MD1

As you see in Figure 1, I select MonoDroid Application on the project templates, enter my project nameHelloAndroid and click OK. This action will create a new project and add default files and code to the project as shown in Figure 2.


MD2


The default file opened in the editor is Activity1.cs.

If you look at the code of Activity1 class listed in Listing 1, you will see there are six Android namespaces are added to the file. The default namespace of the project is the project name you created in Visual Studio.
using System;

using Android.App;

using Android.Content;

using Android.Runtime;

using Android.Views;

using Android.Widget;

using Android.OS;

namespace HelloAndroid

{

[Activity(Label = "HelloAndroid", MainLauncher = true)]

public class Activity1 : 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++); };
}

}

}

Listing 1

The Activity1 class is inherited from the Activity class. Each Android application must have at least one Activity. The class also has an overridden OnCreate method. This is the most useful method and gets executed when an application starts. You should write all initialization and UI related code here. Before we discuss this in more details, let's take a look at the other files in the project.

MD3

If you look at the Solution Explorer more closely (See Figure 3), you will notice Assets, Resources andValues folders. You can also expand these folders to see what default files are added to the project. We are going to discuss these files one at a time.

Before we get into more details, let's add code for our Hello Android display on the screen. I change code of the OnCreate method and add a TextView object and set it's Text property to Hello Android!. The TextView object works as a TextBox control. It is used to display and manage text on the screen.
protected override void OnCreate(Bundle bundle)
{

base.OnCreate(bundle);
var tv = new TextView (this);

tv.Text = "Hello, Android!";

// Set our view from the "main" layout resource

SetContentView(tv);

}

Listing 2

The SetContentView method is responsible for pushing and displaying the contents to the screen.



Now let's build and run the application. Select Build and Run menu item in Visual Studio.

First thing you will see is a screen to select devices. If you have an Android enabled device attached to your computer, you will see that listed here. I use the emulator for testing. To view all emulator images, click on the Start emulator image link on the screen.


MD4


This action will load all the emulator images on your computer. As you can see from Figure 5, I have two emulator images on my computer.

MD5

Now click OK button. After that, you see a screen with various options that checks your emulator and deploys the latest application on the device.


MD6


Once an application is successfully deployed, you can go to Applications and search for it. I search and find HelloAndroid application on my device. See Figure 7.


MD7


Summary

MonoDroid is a framework that is used to build Android based mobile applications using C# and .NET. In this tutorial, we learned how to get started with the MonoDroid framework and Android SDK and build and deploy a simple Android based application.

Tuesday, 12 April 2016

What is Android and Why to use it?

Android is an open source and Linux-based operating system. It was first introduced on Nov 5, 2007. It was originally developed by Android Inc. and subsequently purchased by Google.

Basically, Android is thought of as a mobile operating system. But it is not limited to mobile only. It is currently used in various devices such as mobiles, tablets, televisions etc.

Android provides a rich application framework that allows us to build innovative apps and games for mobile devices in a Java language environment.

The Android open-source software stack consists of Java applications running on a Java-based, object-oriented application framework on top of Java core libraries running on a Dalvik virtual machine featuring JIT compilation.
Android

Features of Android


There are numerous features of android. Some of them are listed below:


Connectivity :Android supports multiple connectivity technologies including GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and WiMAX



Storage:  SQLite, a lightweight relational database, is used for data storage purposes



Media support: Android supports various type of audio/video/still media formats like: H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, BMP and WebP



Web browser: The web browser available in Android is based on the open-source Blink (previously WebKit) layout engine, coupled with Chrome's V8 JavaScript engine supporting HTML5 and CSS3



Messaging: SMS and MMS are available forms of messaging, it also include threaded text messaging and Android Cloud To Device Messaging (C2DM) and now support the enhanced version of C2DM, Android Google Cloud Messaging (GCM) is also a part of Android Push Messaging services



Multi-tasking: Multitasking of applications, with unique handling of memory allocation, is available, using this user can jump from one task to another and at the same time various application can run simultaneously



Resizable widgets: Widgets are re-sizable, so users can expand them to show more content or shrink them to save space



Multi-touch: Android has native support for multi-touch which was initially made available in handsets such as the HTC Hero



Wi-Fi: A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-peer connection.



Screen capture: Android supports capturing a screenshot by pressing the power and home-screen buttons at the same time. This features supports after Android 4.0



Android Beam: A popular NFC-based technology that lets users instantly share, just by touching two NFC-enabled phones together



Multi-Language: Android supports multiple languages, also supports single direction and bi-directional text



?


There are so many reasons you should choose Android platform for mobile application development.


  1. Zero/negligible development cost


    The development tools like Android SDK, JDK, and Eclipse IDE etc. are free to download for the android mobile application development. Also Google charge a small fee $25, to distribute your mobile app on the Android Market.


  2. Open Source


    The Android OS is an open-source platform based on the Linux kernel and multiple open-source libraries. In this way developers are free to contribute or extend the platform as necessary for building mobile apps which run on Android devices.


  3. Multi-Platform Support


    In market, there are a wide range of hardware devices powered by the Android OS, including many different phones and tablet. Even development of android mobile apps can occur on Windows, Mac OS or Linux.


  4. Multi-Carrier Support


    World wide a large number of telecom carriers like Airtel, Vodafone, Idea Cellular, AT&T Mobility, BSNL etc. are supporting Android powered phones.


  5. Open Distribution Model


    Android Market place (Google Play store) has very few restrictions on the content or functionality of an android app. So the developer can distribute theirs app through Google Play store and as well other distribution channels like Amazon’s app store.

What do you think?

I hope, now you have better understanding about Android. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.