Android Tutorial
Android tutorial with full example, including Android UI controls, layouts, common application and some FAQs.
Android tutorial with full example, including Android UI controls, layouts, common application and some FAQs.
In Android, you can use Intent.ACTION_SEND to call an existing email client to send an Email. See following code snippets : Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); email.putExtra(Intent.EXTRA_SUBJECT, "subject"); email.putExtra(Intent.EXTRA_TEXT, "message"); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, "Choose an Email client :")); P.S This project is developed in Eclipse 3.7, and tested with Samsung Galaxy S2 (Android …
In Android, you can use SmsManager API or device’s Built-in SMS application to send a SMS message. In this tutorial, we show you two basic examples to send SMS message : SmsManager API SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null); Built-in SMS application Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); …
In Android, you can use PackageManager , hasSystemFeature() method to check if a device has camera, gps or other features. See full example of using PackageManager in an activity class. package com.mkyong.android; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.os.Bundle; import android.util.Log; public class FlashLightActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
In this tutorial, we show you how to turn on/off the phone camera led or flashlight in Android. See code snippets : 1. Turn on camera = Camera.open(); Parameters p = camera.getParameters(); p.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(p); camera.startPreview(); 2. Turn off camera = Camera.open(); Parameters p = camera.getParameters(); p.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(p); camera.stopPreview(); And, put following permission on AndroidManifest.xml. <uses-permission …
A small Android tip to show you how to center button on screen. Wrap button in RelativeLayout, and set following attributes to “true“. android:layout_centerVertical="true" android:layout_centerHorizontal="true" Following is a full example to demonstrate the use of above tip to center a button on screen. 1. Android Layout A button in layout. File : res/layout/main.xml <?xml version="1.0" …
In Android, Toast is a notification message that pop up, display a certain amount of time, and automtaically fades in and out, most people just use it for debugging purpose. Code snippets to create a Toast message : //display in short period of time Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT).show(); //display in long period of time Toast.makeText(getApplicationContext(), …
This tutorial will show you how to debug Android application on a real Android-powered device (mobile phone). Tools and environment in this tutorial : Eclipse IDE 3.7 + ADT Plugin Samsung Galaxy S2 Windows 7 Summary steps to debug on device : Download Google USB Driver (if using Android Developer Phones (ADP)) Download OEM USB …
In this tutorial, we show you how to create a custom dialog in Android. See following steps : Create a custom dialog layout (XML file). Attach the layout to Dialog. Display the Dialog. Done. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. Note You may also interest to read this …
For Android development on real device like Samsung Galaxy S2, you need to install Samsung OEM driver or USB driver. This Android OEM driver documentation will guide you where to download it… but the guide is not easy to follow. Actually, the “Samsung USB driver” is included in the software called “Samsung Kies or PC …
In this tutorial, we will enchance the previous AlertDialog example, to make it able to accept user input, just like a PromptDialog. More specific, this is a custom AlertDialog example. See following steps : Create a prompt dialog layout (XML file). Attach the prompt dialog layout to AlertDialog.Builder. Attach the AlertDialog.Builder to AlertDialog. Done. P.S …
In this tutorial, we show you how to display an alert box in Android. See flowing Steps : First, use the AlertDialog.Builder to create the alert box interface, like title, message to display, buttons, and button onclick function Later attach above builder to AlertDialog and display it. Done. P.S This project is developed in Eclipse …
In this tutorial, we show you how to make a phone call in Android,and monitor the phone call states via PhoneStateListener. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. 1 Android Layout Files Simpel layout file, to display a button. File : res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" …
Android’s WebView allows you to open an own windows for viewing URL or custom html markup page. In this tutorial, you will create two pages, a page with a single button, when you clicked on it, it will navigate to another page and display URL “google.com” in WebView component. P.S This project is developed in …
In this tutorial, we will demonstrates the use of TabLayout to render 4 tabs – “Android”, “Windows”, “Apple” and “BlackBerry”, each tab contains a textview to display a simple message. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. 1. Tab Images Put 4 tab images in “res/drawable” folder. The tab …
In Android, GridView let you arranges components in a two-dimensional scrolling grid. For detail attribute exaplanation, see GridView reference. In this tutorial, we will show you 2 common GridView examples : Normal way, just display text in GridView layout. Create a custom adapter to display image and text in GridView layout. P.S This project is …
In Android, ListView let you arranges components in a vertical scrollable list. In this tutorial, we will show you 2 ListView examples : Normal way to display components in ListView. Custom array adapter to customize the item display in ListView. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. 1. Normal …
In Android, you can configure the starting activity (default activity) of your application via following “intent-filter” in “AndroidManifest.xml“. See following code snippet to configure a activity class “logoActivity” as the default activity. File : AndroidManifest.xml <activity android:label="Logo" android:name=".logoActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> For example, let said you have …
By default, Android SDK or Eclipse ADT plugin are not bundle with any Android’s source code for debugging. In Eclipse IDE, step into any Android class will prompt no source code attach, see following screen : Solution According to this official Android source code article, it’s shocked that we need to use “repo” to download …
In Android, an activity is represent a single screen. Most applications have multiple activities to represent different screens, for example, one activity to display a list of the application settings, another activity to display the application status. Note Refer to this official Android activity article to understand more about Android activity. In this tutorial, we …
In Android, TableLayout let you arranges components in rows and columns, just like the standard table layout in HTML, <tr> and <td>. In this tutorial, we show you how to use TableLayout to arrange button, textview and edittext in rows and columns format, and also demonstrates the use of “android:layout_span” to span view in 2 …
In Android, RelativeLayout let you position your component base on the nearby (relative or sibling) component’s position. It’s the most flexible layout, that allow you to position your component to display in anywhere you want (if you know how to “relative” it). In RelativeLayout, you can use “above, below, left and right” to arrange the …
In Android, you always put either “wrap_content” or “fill_parent” on component’s attribute “layout_width” and “layout_height“, did you wonder what’s the different? See following definition : wrap_content – The component just want to display big enough to enclose its content only. fill_parent – The component want to display as big as its parent, and fill in …
In Android, LinearLayout is a common layout that arranges “component” in vertical or horizontal order, via orientation attribute. In additional, the highest “weight” component will fill up the remaining space in LinearLayout. In this tutorial, we show you how to use LinearLayout to display 3 buttons in vertical and horizontal order, and also how “weight” …
Here’s a code snippet to show you how to use “android.content.Intent” to open an specify URL in Android’s web browser. button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://mkyong.com")); startActivity(intent); } }); Note For full example, please refer to this – Android button example. References Android Button JavaDoc Android …
In Android, just use “android.widget.Button” class to display a normal button. In this tutorial, we show you how to display a normal button, add a click listener, when user click on the button, open an URL in your Android’s internet browser. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. Note …
In last Android tutorial, you use “ImageButton” to display a “Button” with a customized background image easily. However, you can do more than that just a simple image, Android allow you to change the button’s image depends on different states like button is focused or button is pressed. This example is referenced from this Android …
In Android, you can use “android.widget.ImageButton” to display a normal “Button“, with a customized background image. In this tutorial, we show you how to display a button with a background image named “android_button.png“, when user click on it, display a short message. As simple as that. Note You may also like this Android ImageButton selector …
In Android, you can use “android.widget.ImageView” class to display an image file. Image file is easy to use but hard to master, because of the various screen and dpi in Android devices. Note Please refer to this official Android’s “Drawable Resource” and “Screen Support” article for better understand of how image works in Android. In …
In Android, progress bar is useful to tell user that the task is takes longer time to finish. In this tutorial, we show you how to display a progress bar dialog to tell user that your task is running, and also how to increase the progress bar status until the task is completed. Note Refer …
In Android, the AnalogClock is a two-handed clock, one for hour indicator and the other for minute indicator. The DigitalClock is look like your normal digital watch on hand, which display hours, minutes and seconds in digital format. Both AnalogClock and DigitalClock are UNABLE to modify the time, if you want to change the time, …
In Android, you can use “android.widget.TimePicker” class to render a time picker component to select hour and minute in a pre-defined user interface. In this tutorial, we show you how to render time picker component via android.widget.TimePicker in current page, and also in dialog box via android.app.TimePickerDialog. In addition, we also show you how to …
In Android, you can use “android.widget.DatePicker” class to render a date picker component to select day, month and year in a pre-defined user interface. In this tutorial, we show you how to render date picker component in current page via android.widget.DatePicker, and also in dialog box via android.app.DatePickerDialog. In addition, we also show you how …
In Android, you can use “android.widget.Spinner” class to render a dropdown box selection list. Note Spinner is a widget similar to a drop-down list for selecting items. In this tutorial, we show you how to do the following tasks : Render a Spinner in XML, and load the selection items via XML file also. Render …
In Android, you can use “android.widget.RatingBar” to display rating bar component in stars icon. The user is able to touch, drag or click on the stars to set the rating value easily. In this tutorial, we show you how to use XML to display a rating bar, few textviews and a button. When user click …
In Android, you can use “android.widget.EditText“, with inputType=”textPassword” to render a password component. In this tutorial, we show you how to use XML to create a password field, label field and a normal button. When you click on the button, the password value will be displayed as a floating message (toast message). P.S This project …
In Android, the “android.widget.ToggleButton” is a special class to render a button which has only two states, for example, “on and “off”. It’s best alternative to radio buttons to turn on or turn off a function. In this tutorial, we show you how to use XML to create two toggle buttons and a normal button, …
In Android, you can use “android.widget.RadioButton” class to render radio button, and those radio buttons are usually grouped by android.widget.RadioGroup. If RadioButtons are in group, when one RadioButton within a group is selected, all others are automatically deselected. In this tutorial, we show you how to use XML to create two radio buttons, and grouped …
In Android, you can use “android.widget.CheckBox” class to render a checkbox. In this tutorial, we show you how to create 3 checkboxes in XML file, and demonstrates the use of listener to check the checkbox state – checked or unchecked. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. 1. Custom …
In Android, you can use “EditText” class to create an editable textbox to accept user input. This tutorial show you how to create a textbox in XML file, and demonstrates the use of key listener to display message typed in the textbox. P.S This project is developed in Eclipse, and tested with Android 2.3.3. 1. …