Sunday 24 April 2016

Best way to start Android App Development

There may be many Blog on how to start Android App Development. Here I will mention the best way to start Android App Development . Following are some points but you should have basic knowledge of Programing in Java Programing language.

  • Follow one Book.
  • Read basics from official android developer website.
  • Use StackOverFlow for all your meaning full queries.
  • Use of Github for repository management .
  • Email me for any queries (nitin_sharma639@yahoo.com)


  • Follow one Book : There are many books available in market. My personal favourite is  Beginning Android by Mark L. Murphy .There are other Good books by Reto Meire .You can find here . Following a book will give you step by step instructions on how to start development . A book can not contain all the things there for you also have read basics from the official android developer website.                                                                                                                                                                                                                                                                                                                                                                                                                  
  • Read basics from official android developer website : As I mention book alone is not the best way to get started. You should also get your basics correct from official Android Developer Website . which is here http://developer.android.com/. There are documentation of all the components of Android Software and Hardware . If you are using any Component in your app you must know the documentation of that Component.

  • Use  Stack Over Flow for all your meaning full queries : When you are starting app development you will face some problems.There is a website stackoverflow. Where many developer are register. You can register there to ask your question. There are many developer who can help you with your queries .

  • Use of Github for repository management : You can use any version control system to create different version of your project .When developing a project some time you create code which is not working but you want revert back to the previous version of your project. You can use any version control system. I prefer Git Hub for VCS.

Monday 1 February 2016

How to create Application using Material Design?

Here I will discuss what are the Views and Layouts which are used in Material Design

If you are new to Material Design. you can check Material Design by Google. Following are the some of the Views and Layout which are used to create Material Design.

  1. CoordinatorLayout 
  2. Floating action button
  3. NavigationView
  4. Snackbar
  5. CollapsingToolbarLayout
These are all Views and  Layouts which can be used to integrate Material Design in your Application.To ingrate all these views you need to include only one Library which is Android Design Support Library.You can include this library in your app using following statement in your build.gradle file in android studio.

compile 'com.android.support:design:22.2.0'
I will explain further about these Views and Layouts in next tutorials. 
For any query Email me : nitin_sharma639@yahoo.com

Wednesday 20 January 2016

How to set Alarm in Android programmatically ?


To set an alarm in android you have use AlarmManager class. Following is the code to set alarm.

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent );
In the above example cal is object of Calendar.
you can instantiate it as following :
Calendar cal=Calendar.getInstance(); cal.set(Calendar.MONTH,5); cal.set(Calendar.YEAR,2016); cal.set(Calendar.DAY_OF_MONTH,29); cal.set(Calendar.HOUR_OF_DAY,17); cal.set(Calendar.MINUTE,30);
 There is little thing to mention here this alarm will fire on 29 june 2016 because the months are zero-based. 

following Is the code of class AlarmSetter 


import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.ListActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;


public class AlarmSetter extends Activity {
   Button btn;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   setContentView(R.layout.yourlayout);
   Calendar cal=Calendar.getInstance();
   cal.set(Calendar.MONTH,5);
   cal.set(Calendar.YEAR,2011);
   cal.set(Calendar.DAY_OF_MONTH,29);
   cal.set(Calendar.HOUR_OF_DAY,17);
   cal.set(Calendar.MINUTE,30);

  
    Intent intent = new Intent(this, Mote.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 1253, intent, PendingIntent.FLAG_UPDATE_CURRENT|  Intent.FILL_IN_DATA);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent );
    Toast.makeText(this, "Alarm Set.", Toast.LENGTH_LONG).show();
}
You have to to declare the class AlarmSetter in the Android Manifest file.
In the above example We are declaring PendingIntent.
In the PendingIntent.getBroadcast(this.getApplicationContext(), 
1253,intent, PendingIntent.FLAG_UPDATE_CURRENT|  Intent.FILL_IN_DATA);

In this there are four parameters 

1) Application Context
2) Unique id
3) intent
4) Type of BroadcastReciever.


You do need to much worry about Application context,
Unique id (choose any random id),Type of BroadcastReciever
but the third parameter is important. In the Intent you will 
specify the BroadcastReciever which will trigger when the 
alarm will fire. We have declared Mote which is subclass 
of BroadcastReciever  
Following is the Source Code of Mote class

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class Mote extends BroadcastReceiver{

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
  
}



}

Do not forget to Declare Mote BroadcastReceiver in Manifest 
<receiver  android:name=".Mote"></receiver>

Thanks
For any query feel free to contact me at nitin_sharma639@yahoo.com