Friday, June 28, 2013

Android's Text to Speech Tutorial

This is a sample activity which shows How to use Android’s Text to Speech capabilities. Text to Speech was introduced in Android 1.6, so when you create your new Android project make sure your minimum required SDK is set to Android 1.6 (or API level 4).

Basic description of algorithm in step by step form:
1.) Create a Project TextToSpeech.
2.) Put the following code snippet in res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
<EditText android:id="@+id/input_text"

<Button android:id="@+id/speak_button"
    android:text="Speak to me"

Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. MyTextToSpeech. Enter following information:
Project name: TextToSpeech
Build Target: Android APIs 2.2
Application name: TextToSpeech
Package name:
Create Activity: TextToSpeech

Put the following code in src/


import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TextToSpeech extends Activity implements OnInitListener{
    /** Called when the activity is first created. */
    private int MY_DATA_CHECK_CODE = 0;

    private TextToSpeech tts;

    private EditText inputText;
    private Button speakButton;

    public void onCreate(Bundle savedInstanceState) {

        inputText = (EditText) findViewById(;
        speakButton = (Button) findViewById(;

        speakButton.setOnClickListener(new OnClickListener() {         
        public void onClick(View v) {
           String text = inputText.getText().toString();
           if (text!=null && text.length()>0) {
            Toast.makeText(MyTextToSpeech.this, "Saying: " + text, Toast.LENGTH_LONG).show();
            tts.speak(text, TextToSpeech.QUEUE_ADD, null);
        Intent checkIntent = new Intent();
        startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // success, create the TTS instance
            tts = new TextToSpeech(this, this);
        else {
            // missing data, install it
            Intent installIntent = new Intent();

    public void onInit(int status) {       
      if (status == TextToSpeech.SUCCESS) {
        Toast.makeText(MyTextToSpeech.this, "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();
      else if (status == TextToSpeech.ERROR) {
        Toast.makeText(MyTextToSpeech.this, "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();

Run the Application
Output –The final output:


Friday, June 14, 2013

Running Your App - BYFAA

If you followed the previous lesson to create an Android project, it includes a default set of "Hello World" source files that allow you to immediately run the app.
Before you run your app, you should be aware of a few directories and files in the Android project:
The manifest file describes the fundamental characteristics of the app and defines each of its components. You'll learn about various declarations in this file as you read more training classes.
Directory for your app's main source files. By default, it includes an Activity class that runs when your app is launched using the app icon.
Contains several sub-directories for app resources. Here are just a few:
Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities.
Directory for files that define your app's user interface.
Directory for other various XML files that contain a collection of resources, such as string and color definitions.

Run on the Emulator

Whether you're using Eclipse or the command line, to run your app on the emulator you need to first create anAndroid Virtual Device (AVD). An AVD is a device configuration for the Android emulator that allows you to model different devices.
Figure 1. The AVD Manager showing a few virtual devices.
To create an AVD:
  1. Launch the Android Virtual Device Manager:
    1. In Eclipse, click Android Virtual Device Manager from the toolbar.
    2. From the command line, change directories to<sdk>/tools/ and execute:
      android avd
  2. In the Android Virtual Device Manager panel, click New.
  3. Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default).
  4. Click Create AVD.
  5. Select the new AVD from the Android Virtual Device Manager and click Start.
  6. After the emulator boots up, unlock the emulator screen.
To run the app from Eclipse:
  1. Open one of your project's files and click Run  from the toolbar.
  2. In the Run as window that appears, select Android Application and click OK.
Eclipse installs the app on your AVD and starts it.

Get ready for the next tutorial which is very interesting

Friday, June 7, 2013

Building Your First Android App (BYFAA)

Before you start this class, be sure you have your development environment set up. You need to:
  • Download the Android SDK.
  • Install the ADT plugin for Eclipse (if you’ll use the Eclipse IDE).
  • Download the latest SDK tools and platforms using the SDK Manager.

If you haven't already done these tasks, start by downloading the Android Sdk from the link below
Once you've finished the setup, you're ready to begin this class.
This class uses a tutorial format that incrementally builds a small Android app that teaches you some fundamental concepts about Android development, so it's important that you follow each step.
First Step: Creating Android Project
An Android project contains all the files that comprise the source code for your Android app. The Android SDK tools make it easy to start a new Android project with a set of default project directories and files.
Note: You should already have the Android SDK installed, and if you're using Eclipse, you should also have the ADT plugininstalled (version 21.0.0 or higher). If you don't have these, follow the guide to Installing the Android SDK before you start this lesson.
1. Click New in the toolbar.
2. In the window that appears, open the Android folder, select Android Application Project, and click Next.
    3. Fill in the form that appears:
           Application Name: Is the app name that appears to users
           Project Name: Is the name of your project directory
           Package Name: Is the package namespace for your app
    Leave the rest of detail then Click Next
    4. On the next screen to configure the project, leave the default selection and Click Next
    5. The next screen can help you create a launcher icon for your app. You can customize an icon in several ways and the tool generates an icon for all screen densities. Click Next
    6. Now you can select an activity template from which to begin building you app. For this project, select BlackActivity and Click Next.
    7. Leave all the details for the activity in their default state and click Finish.
    Your Android project is now set up with some default files and you're ready to begin building the app.

    Get ready for the next lesson of BYFAA.

Thursday, June 6, 2013


Android phones, based on the mobile operating system from Google, have taken over the world. But there is more to Android than just a popular phone platform.
Android rule the world
The Android OS has appeared on wearable devices such as smart watches and Google Glass, as well as on Cameras and a book-shaped PC made of cardboard. The operating system is open source, so it could be show up almost anywhere.
Various phone makers have had a major part to play in the story of Android, with HTC and Sumsung leading the way at various times. Motorola Mobility, now owned by Google, is obviously going to have a key role in future.

Try out this quiz

Samsung S4 Life companion

Make your life richer, simpler and more fun.

As a life companion, the new Samsung Galaxy S4 helps bring us closer and captures those fun moments when we are together. Each feature has been designed to simplify and enrich our daily lives and the phone is even smart enough to monitor our health and well-being. To put it simply, the Samsung Galaxy S4 is there for you.
Amazing feature - Group Play - Share Music