Search in Help for developer site.

Thursday 28 July 2016

Create simple android mobile application using Xamarin and Visual Studio

1. Overview

This article gives an introduction to how to create your first android mobile application using Xamarin. Xamarin allows .NET developers to develop any android/IOS/windows apps using their existing IDE and language like visual studio and C#.
After reading this article you will be able to develop a simple android mobile application using c# with Xamarin which adds any two int number and displays result in an alert box.

2. Prerequisites

 I am assuming that you have already installed Xamarin tool for visual studio and you have installed android SDK and API.

3. Step by step creating your first android mobile application

Let’s start to create android application with visual studio and Xamarin, to create go to
File->New->Project. In the left list under Visual C# select android and then select Blank App (Android) as shown in below screenshot.



Then give any appropriate project name, I’m giving AddTwoNumber as a project name after this click Ok to continue create project

4. Project Structure

When your project has been created, you will see project structure as shown in below screenshot.

  • As you can see layout folder under Resources, to create any layout for android apps.  Now open Main.axml file to see design and source part.
  • To add two number we need two TextBox and 1 button, you can create these control using drag and drop method or using source code. In this article I will use source code to create these controls.

design view

Main.axml Source Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="fill_parent">
    <EditText
        android:id="@+id/txtNum1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/txtNum2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/MyButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ADD" />
</LinearLayout>

·              Now open MainActivity.cs file to write our C# code to function it.

[Activity(Label = "AddTwoNumber", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            
            FindViewById<Button>(Resource.Id.MyButton).Click += MyButton_Click;
        }

        private void MyButton_Click(object sender, EventArgs e)
        {
            int txtNum1 = Convert.ToInt32(FindViewById<EditText>(Resource.Id.txtNum1).Text);
            int txtNum2 = Convert.ToInt32(FindViewById<EditText>(Resource.Id.txtNum2).Text);
            int result = txtNum1 + txtNum2;
            //showing result in alert message
            new AlertDialog.Builder(this)
                .SetMessage("Result=" + result)
                .SetTitle("Message")
                .Show();

        }
    }
  • That’s it we are done with coding now time to launch our application
  • To run and test this application I will use my android phone  because android emulator runs very slow
  • When you connect your android phone to your PC it will automatically detect your phone it will be shown as per below screenshot


·         Note:-Make sure your phone is connected in USB debugging mode.
·         Now run with F5 and this application will be installed in your mobile automatically.
·         These are the screenshot on my mobile.




5. What do you think

hello readers I hope you liked this post to create a very simple android mobile application using Xamarin tool and visual studio. What do you think about it, let me know your concerns and queries, just write it down in comments and if you like it share it.
  


Monday 25 July 2016

How to send HTML email in outlook programmatically using c#.

In outlook we can send HTML emails, when we add some HTML code outlook can convert that HTML to design. For that we need to change the mail format to HTML in outlook setting.

For eg. if you use the below HTML code in your mail body
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<p>Name</p>
<span>Add</span>
</body>
</html>

Then outlook will convert your message like below

My First Heading

My first paragraph.
Name
Add

This can be done by C#. When you have a fixed HTML format but some fields will change such as name, address etc then u can use this code to send HTML mail.
For that you need to add a reference to "Microsoft.Office.Interop.Outlook"
Use this code in your mail sending event.



            StringBuilder mailbody = new StringBuilder();
            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

            Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            oMailItem.To = "xyz@gmail.com";
            oMailItem.Subject = "Subject";
            mailbody.Append("<html>");
            mailbody.Append("<head>");
            mailbody.Append("<title>Page Title</title>");
            mailbody.Append("</head>");
            mailbody.Append("<body>");
            mailbody.Append("<h1>My First Heading</h1>");
            mailbody.Append("<p>My first paragraph.</p>");
            mailbody.Append("<p>Name</p>");
            mailbody.Append("<span>Add</span>");
            mailbody.Append("</body>");
            mailbody.Append("</html>");
            oMailItem.HTMLBody = mailbody.ToString();
            // body, bcc etc...
            //For adding cc and bcc

            //oMailItem.Send();
            //To send mail.

            oMailItem.Display(true);//This will open outlook before sending the mail.





Please comment for more explanation.

Monday 18 July 2016

Explanation of Web Development Modules

This blog explain end to end development modules very well. Go through it and ask questions if any doubt.

Front End: You've got basically anything you want, nowadays this is usually web, hybridish or native mobile (can also be a desktop GUI application).

The common languages are Angular, Ember, React, Aurelia, Boostrap, and whatever else. These are called front end frameworks. They are written in Javascript which is basically what makes dynamic things happen on HTML (otherwise static) web pages, and CSS is used for styling.

HTML provides the core elements like buttons, input boxes, etc. and JavaScript and CSS let you style them to make them look pretty. JS also makes everything dynamic. You know.. if you hover over a name on facebook and it shows you info on that person? That's JS at work. You can actually view this on any page by right clicking and hitting "Inspect Element" or something like that.

You can view the raw HTML framework of every page by hitting Ctrl+U or right clicking and hitting View Source.

For styling, you've got like SASS and LESS for that (look up those + CSS for more info), along with others. Bootstrap also does a lot of this stuff for you and looks dope. Check it out.

If this is going on a phone, it can also be done with something like React Native, which has the benefit of working on both iOS and Android without additional development needed. Ionic is similar.

These sorts of things just use JS, often with one of the frameworks I just mentioned for the code.

Beyond that you have standard native mobile development languages like Swift (nice) and Objective-C (a pain) for iOS, and Android Java (good) for Android.

Native apps are installed locally onto the phone. You can use them offline. They may access online resources, but the app is fully offline. Also they are not coded in a web language.

Hybrid apps are generally kind of half and half. They have a native dock if you will, but they are written in web languages (even if you can access some data offline), and generally sync with the web regularly.

Web apps are only viewed through a browser without a native "dock" so to speak.

Native apps can take full advantage of all the phone's hardware. Hybrid apps can take some advantage of this, and web apps are limited to what the browser can provide.

Data Transport:

All of the info you need comes up from the back end through a data transport layer. This can be anything, but typically it's done through a REST API.

They look like this:

yourdomain.com/api/credentials/get

yourdomain.com/api/credentials/set

You can do this however you like. You don't need the fancy standards. Often this is done using POST, but if you need to pass a lot of data all the time, you're better off opening a socket. (Look all this shit up for more info if you want it).

Random side note: sockets + JSON + Node.js makes a decent back end server for gaming.

JSON is an object notation. Looks like this:

{"propertya":5, "propertyb":"value"}

A bit more complex than that, but not much more. You use that to pass info back and forth like if the front end needs someone's first and last name, you might hit a back end REST API called yourdomain.com/api/names/get and it might return something like this to the front end which you can use:

{"first_name":"Carlos", "last_name":"La Borde"}

XML isn't much different, though nicer for viewing out of the box IMO. It's a bit heavier:

<xml ..../>
<firstname>Carlos</firstname>
<lastname>La Borde</lastname>
</xml>

Because it's a bit heavier, it's fallen a bit out of fashion, but it still gets the job done effectively. K... now the back end.

Back End:

A lot is made of web languages, but truth is, you can use whatever you like. I have some back end systems hooked up to REXX (ancient IBM language) and they run like a charm.

The standard ones you'll hear a lot about nowadays are PHP, Ruby (+on Rails), Python, and Node.js.

All of them are good except PHP which is still good in smaller projects and for newbies, but IMO teaches you bad habits and has some serious flaws. I'm not saying you can't use it, just read up and consider your use cases before you invest a lot of time in it. A lot of people get bogged down with PHP because it's easy and don't want to change.

IMO Ruby, Python, and Node work brilliantly with REST out of the box, and Node works brilliantly with JSON, because.. well, it's JS.

You're not limited to those. Java and C# also work reasonably well in the back end, though they're a bit heavier. Personally I'd hold off using them unless it was for a big enterprise thing.

Also.. like I said technically you can use any language (C++ works too). Hell, you can literally use goddamn Assembly (I know of a guy who does).

DB Transport Layer:

To get at stuff in the back end.. You need a way to connect your web language to a DB. For some languages and DBs, this is a piece of cake.

With Node and MySQL or mongo you just use npm to install a package, include it and you're good to go.

For some other languages, like Java or DB2, it becomes a bit of a pain. You may have to use something like ODBC or JDBC (which you install on your server and pick your DB). The details of those of the scope of this answer, but they are out there and those are what to look for if you're stuck trying to connect a DB to your language.

Databases:

OK now onto the databases themselves. There are a shitload of pros and cons and best practices for different use cases. This is kind of important, so do the research given what you're trying to do.

The standard ones are SQL. This stands for Structured Query Language. Basically that means in your language you create a string called a query and run it against this database and it returns what you asked for. This is in a semi English language.

Here's a sample query:

SELECT * FROM users WHERE email_address='carloslaborde@domain.com'

The * means "all" in this context.

There's a lot more to it than that, but you can do a lot only knowing a little.

Basically all of these suckers are structured like tables with columns. So users in this context is a table, and email_address is a column. The SELECT * piece will select an entire row of data where the email_address matches.

The rest of that row might look like:

first_name | last_name | email_address
"Carlos" | "La Borde" | "carloslaborde@domain.com"

See what I'm saying? There could be a hundred rows with different data, but the select grabs just this one with this column.

Think of it like slicing and dicing an Excel sheet. That's almost exactly what it is.

Now.... You also have NoSQL DBs. These have made a big splash in the past few years. Personally I think people often pick them blindly because they're new rather than logically assessing if they would benefit their use case.

Anyways... these include popular names like MongoDB and Redis.

Mongo is popular because it's part of the MEAN stack. M = Mongo, E = Express (couples well with Node), A = Angular (a JS front end framework we mentioned earlier), and N = Node.

I will say that NoSQL DBs are good for holding onto data that comes in chunks. Like (social media) post data, for instance. They are easy to scale and shard nicely in ways that SQL DBs really struggle with, and they can be wicked fast and kicking back an entire object (Mongo plays nice with Node and Angular because these objects are all JSON).

That said, they are shitty if you need to join or perform similar complex data operations (e.g. getting totals would be a bit of a pain, but trivial in SQL).

If you're on Bluemix, Cloudant is a good choice of NoSQL DB that I love using (when the use cases are right).

I mentioned Redis, so I'll chat a bit about that. It's not just NoSQL, it's called a key store or a key value database, which means you just send in pairs of data. It's wicked fast and relies on in-memory caching.

There are also queue DB structures that I didn't mention here (like Rabbit/MQ). These are good for temporarily holding onto a lot of data you need to parse very quickly. Redis is often used to enable these.

Short Introduction of Apache Cordova

This article will help to understand about cross platform Apache cordova. here is only short introduction of cordova.

Apache Cordova

Cordova wraps your HTML/JavaScript app into a native container which can access the device functions of several platforms. These functions are exposed via a unified JavaScript API, allowing you to easily write one set of code to target nearly every phone or tablet on the market today and publish to their app stores.

Supported Platforms

The following shows the set of development tools and device APIs available for each mobile platform. The device APIs listed here are provided by the core plugins, additional APIs are available via third-party plugins. Column headers display the CLI's shorthand names.




Android


blackberry10


ios

Ubuntu
wp8
(Windows Phone 8)
windows
(8.1, 10,
Phone 8.1)


    ü  Mac, Windows, Linux
     ü Mac, Windows, Linux
      ü Mac
         üUbuntu
     
üWindows
     ü       


     ü   (see details)
     ×

     ü(see details)
   ×
    ×
  ×


     ü(see details)
     ü(see details)
ü(see details)üü(see details)ü



Core Plugins

The most current version of the Cordova Core Plugin APIs are found in their respective GitHub repositories linked to below:

General Plugin Discovery

You can also find a full directory of Cordova Plugins on the Cordova Plugin page.