Posts

Creating a DatePicker in Android

Android gives controls for the user to pick a date as ready-to-use dialogs. Each date picker gives controls for selecting each part of the date(day, month, year). Using this picker helps ensure that your users can pick a date is valid, formatted correctly, and adjusted to the user's locale. We can get DatePickerDialog through DialogFragment and DatePickerDialog.OnDateSetListener. Create Android Project with name as "DatePickerDemo" with package name "com.com.datepickerdemo". Create Activity with name as "DatePicker" and it will fetch date. This is the code for DatePicker. package com.com.datepickerdemo; import java.util.Calendar; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; public...

Creating a TimePicker in Android

Android gives controls for the user to pick a time as ready-to-use dialogs. Each picker gives controls for selecting each part of the time (hour, minute, AM/PM). Using these pickers helps ensure that your users can pick a time is valid, formatted correctly, and adjusted to the user's locale. We can get TimePickerDialog through DialogFragment and TimePickerDialog.OnTimeSetListener. Create Android Project with name as "TimePickerDemo" with package name "com.etr.timepickerdemo". Create Activity with name as "MainActivity" and it will fetch time. This is the code for MainActivity. package com.etr.timepickerdemo; import java.util.Calendar; import android.app.Dialog; import android.app.TimePickerDialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.text.format.DateFormat; import android.view.Menu; import android.view.View; import android.widget.Butt...

Record Video in Android using Camera Intent

We can record video in android using camera intent.An intent action type of MediaStore.ACTION_VIDEO_CAPTURE or MediaStore.ACTION_IMAGE_CAPTURE can be used to capture images or videos or without directly using the Camera object. Create Android Project with name as "StartVideo" with package name "com.etr.startvideo". Create Activity with name as "VideoActivity" and it will start video record. This is the code for VideoActivity. package com.etr.startvideo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class VideoActivity extends Activity { public static final int code = 1111; Button start_video; @Override protected void onCreate(Bundle savedInstanceState) { try { super...

Captured Image in Android using Camera Intent

We can capture image in android using camera intent.An intent action type of MediaStore.ACTION_VIDEO_CAPTURE or MediaStore.ACTION_IMAGE_CAPTURE can be used to capture videos or images without directly using the Camera object. Create Android Project with name as "StartCamera" with package name "com.etr.startcamera". Create Activity with name as "CameraActivity" and it will start camera. This is the code for CameraActivity. package com.etr.startcamera; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class CameraActivity extends Activity { public static final int code = 1337; Button start_camera; @Override protected void onCreate(Bundle savedInstanceState) { try { super....

Programmatically turn ON/OFF WiFi on Android device

WifiManager provides the primary API for managing all aspects of WI-FI connectivity.we can get WifiManager instance through  Context.getSystemService(Context.WIFI_SERVICE). WifiManager is used to find the currently active Wi-Fi network and change the Wi-Fi State. Create Android Project with name as "TurnOnWIFI" with package name "com.etr.turnonwifi". Create Activity with name as "MainActivity" and it will turn ON/OFF Wi-Fi. This is the code for MainActivity. package com.etr.turnonwifi; import android.app.Activity; import android.content.Context; import android.net.wifi.WifiManager; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { Button start, stop; @Override protected void onCreate(Bundle savedInstanceState) { try { su...

AlarmManager in Android

AlarmManager is used to start the future actions.Example: Birthday SMS scheduler . AlarmManager is a class which is used to access the system alarm service.These allow you to schedule your application to be run at some point in the future.When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. When the device is in sleep mode registered alarms are retained,but will be cleared if it is turned off and rebooted.You do not instantiate this class directly, instead of that we can get it through Context.getSystemService(Context.ALARM_SERVICE). Create Android Project with name as "AlarmManagerDemo" with package name "com.etr.alarmmanagerdemo". Create Activity with name as "AlarmManagerActivity" and it will start the Alarm. This is the code for AlarmManagerActivity. package com.etr.alarmmanagerdemo; import android.app.Activity; import andr...

Timer in Android

Timers will schedule and execute the tasks(one-shot or recurring).Each timer has one thread,where the tasks executes sequentially. When this thread is busy running a task, runnable tasks may be subject to delays. One-shot are scheduled with either a absolute time or after a relative delay. Recurring tasks are scheduled to run at an fixed period or a fixed rate. Fixed-period execution: It Runs based on the start time of the previous run. Fixed-rate execution: It doesn't based on the start time of the previous run. cancel() is used to stop the Timer.  Create Android Project with name as "TimerDemo" with package name  "com.android.timerdemo". Create Activity with name as "TimerDemo" and it will start the Timers. This is the code for TimerDemo. package com.android.timerdemo; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import...