Sunday, 24 April 2016

Deploy and Debugging the Android applications in Redmi MI Note mobile from visual studio using C#

In this post we are going to see how to Deploy and debugging a android application  in Android device,  I am deploying the application in my mobile phone which is Redmi MI Note , KitKat version.

Initially my mobile was not detect in my machine to deploy and debug the application, this is because of not enable the developer option in my mobile. Here HiAndroid is the App Name





First we see how to enable the Developer option in the Xiaomi Redmi MI Note ....Before enable the USB debugging in your device , you have to enable developer option, developer options disabled as default.

Step 1 : Unlock Redmi Note
Step 2: From Apps , Go to settings
Step 3: Under settings, scroll down to the bottom of the page and click about phone
Step 4: Tap About Phone
Step 5: Under the About phone, we can see the MIUI version
step 6 : Now Tap MIUI version 7 times continuously, to enable the developer options
Step 7: Now you can see the message " Now you are a developer" , Now enable the USB debugging
Step 8: Go to Settings
Step 9: under settings, go to the bottom, to find the Additional settings, 
Step 10: Tap on additional settings,
Step 11: Tap on Developer options
Step 12: Under the Developer options, you can see the Enable USB Debugging Options,
Step 13: Now enable the USB Debugging option


After enable the developer option connect it with the machine , now you can able to see the Device in visual studio, along with other emulators.








Now you can run the application by click the device button, it will deploy the application in mobile and start running, Now here i am created a debug point on button click, so whenever user click on the button , it will hit back to the visual studio from the device.







 

Now in my code i have debug point on button click.

Layout:
***************
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace ToastAndroid
{
    [Activity(Label = "HiAndroid", MainLauncher = true, Icon = "@drawable/raj")]
    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);

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

        }

        private void Button_Click(object sender, EventArgs e)
        {
            Toast.MakeText(this"Hi How are you ?"ToastLength.Long).Show();
        }
    }
}



Main.axml:
********************
<?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/Submit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/Submit" />
</LinearLayout>


When users click on the button submit in application, the control moves from phone to computer and hits the debugging point , then after debugging it results in toast message "Hi, How are you ?"







The result of this application is a simple Hi toast message.





You can see the app in the start page like below in the name of " Hi Android"






From this post you can see how to deploy and debug the android application in Redmi MI Note mobile from Visual studio using C#