Mostrando entradas con la etiqueta Mariano Salvetti. Mostrar todas las entradas
Mostrando entradas con la etiqueta Mariano Salvetti. Mostrar todas las entradas

jueves, 14 de junio de 2012

What is Android?


Android Operation System

Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM).
Android is officially guided by the Open Handset Alliance but in reality Google leads the project.

Android supports 2-D and 3-D graphics using the OpenGL libraries and supports data storage in a SQLite database.
Every Android applications runs in its own process and under its own user id which is generated automatically by the Android system during deployment. Therefore the application is isolated from other running applications and a misbehaving application cannot easily harm other Android applications.

Important Android components

An Android application consists out of the following parts:
  • Activity - represents the presentation layer of an Android application, e.g. a screen which the user sees. An Android application can have several activities and it can be switched between them during runtime of the application.
  • Views - the User interface of an Activities is built with widget classes which inherit fromandroid.view.View. The layout of the views is managed byandroid.view.ViewGroups. Views often have attributes which can be used to change their appearance and behavior.
  • Services - perform background tasks without providing an UI. They can notify the user via the notification framework in Android.
  • ContentProvider - provides data to applications, via a content provider your application can share data with other applications. Android contains a SQLite DB which can serve as data provider
  • Intents - are asynchronous messages which allow the application to request functionality from other services or activities. An application can call directly a service or activity (explicit intent) or ask the Android system for registered services and applications for an intent (implicit intents). For example the application could ask via an intent for a contact application. Applications register themselves to an intent via an IntentFilterIntentsare a powerful concept as they allow the creation of loosely coupled applications.
  • BroadcastReceiver - receives system messages and implicit intents, can be used to react to changed conditions in the system. An application can register as aBroadcastReceiver for certain events and can be started if such an event occurs.
  • Widgets - interactive components primary used on the Android homescreen to display certain data and to allow the user to have quick access the the information

Other Android components are Live Folders and Android Live Wallpapers. Live Folders display data on the homescreen without launching the corresponding application.

Dalvik Virtual Machine

Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tooldx which allows to convert Java Class files into dex (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program aapt (Android Asset Packaging Tool) To simplify development Google provides the Android Development Tools (ADT) for Eclipse. The ADT automatically performs the conversion from class to dex files and creates the apk during deployment.

Security and permissions

Android defines certain permissions for certain tasks. For example if the application wants to access the Internet it must define in its configuration file that it would like to use the related permission. During the installation of an Android application the user receives a screen in which he needs to confirm the required permissions of the application.

domingo, 10 de junio de 2012

ANDROID NDK GETTING STARTED


Android NDK Programming Tutorial, Learn how to install the Android NDK and begin using it. By the end of this tutorial, you will have created your own project that makes a simple call from Java code to native C code.

Prerequisite Experience

Before we get started, we need to take a moment here to discuss the level of this tutorial. It’s flagged as advanced. The reason for this is that we, the authors, are going to assume that you would agree with the following statements:
  1. You are experienced with Java and C.
  2. You are comfortable using the command line.
  3. You know how to figure out what version of Cygwin, awk, and other tools you have.
  4. You are comfortable with Android Development.
  5. You have a working Android development environment (as if this writing, the authors are using Android 2.2)
  6. You use Eclipse or can translate Eclipse instructions to your own IDE with ease.
If you aren’t comfortable with these, you’re welcome to read this tutorial, of course, but you may have difficulties at certain steps that would be resolved by being comfortable with the above. That said, using the NDK is still a process that is prone to problems and issues even if you consider yourself a mobile development veteran. Be aware that you may have to do some troubleshooting of your own before you get everything working smoothly on your development system.
The complete sample project for this tutorial can be downloaded open source code.

A Note About When to Use NDK

So, if you’re reading this tutorial, you may already be considering the NDK for your Android projects. However, we’d like to take a moment to talk about why the NDK is important, when it should be used, and—just as importantly, when it should not be used.
Generally speaking, you only need to use the NDK if your application is truly processor bound. That is, you have algorithms that are using all of the processor within the DalvikVM and would benefit from running natively. Also, don’t forget that in Android 2.2, a JIT compiler will improve the performance of such code as well.
Another reason to use the NDK is for ease of porting. If you’ve got loads of C code for your existing application, using the NDK could speed up your project’s development process as well as help keep changes synchronized between your Android and non-Android projects. This can be particularly true of OpenGL ES applications written for other platforms.
Don’t assume you’ll increase your application’s performance just because you’re using native code. The Java<->Native C exchanges add some overhead, so it’s only really worthwhile if you’ve got some intensive processing to do.

Step 0: Downloading the Tools

Alright, let’s get started. You need to download the NDK. We’ll do this first, as while it’s downloading you can check to make sure you have the right versions of the rest of the tools you need.
Download the NDK for your operating system from the Android site.
Now, check the versions of your tools against these:
  1. If on Windows, Cygwin 1.7 or later
  2. Update awk to the most recent version (We’re using 20070501)
  3. GNU Make 3.81 or later (We’re using 3.81)
If any of these versions are too old, please update them before continuing.

Step 1: Installing the NDK

Now that the NDK is downloaded (it is, right?), you need to unzip it. Do so and place it in an appropriate directory. We put ours in the same directory that we put the Android SDK. Remember where you put it.
At this point, you may want to add the NDK tools to your path. If you’re on Mac or Linux, you can do this with your native path setting. If you’re on Windows using Cygwin, you need to configure the Cygwin path setting.

Step 2: Creating the Project

Create a regular Android project. To avoid problems later, your project must reside in a path that contains no spaces. Our project has a package name of “com.mamlambo.sample.ndk1” with a default Activity name of “AndroidNDK1SampleActivity” – you’ll see these appear again soon.
At the top level of this project, create a directory called “jni” – this is where you’ll put your native code. If you’re familiar with JNI, the Android NDK is heavily based on JNI concepts – it is, essentially, JNI with a limited set of headers for C compilation.

Step 3: Adding Some C Code

Now, within the jni folder, create a file called native.c. Place the following C code in this file to start; we’ll add another function later:
#include   
  • #include
  • #include
  • #define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"
  • void Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_helloLog(JNIEnv * env, jobject this, jstring logThis)
  • {
  • jboolean isCopy;
  • const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy);
  • __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);
  • (*env)->ReleaseStringUTFChars(env, logThis, szLogThis);
  • }
  • This function is actually fairly straightforward. It takes in a Java object String parameter, converts it in to a C-string, and then writes it out to LogCat.
    The name of the function, though, is important. It follows the specific pattern of “Java,” followed by the package name, followed by the class name, followed by the method name, as defined from Java. Every piece is separated by an underscore instead of a dot.
    The first two parameters of the function are critical, too. The first parameter is the JNI environment, frequently used with helper functions. The second parameter is the Java object that this function is a part of.

    Step 4: Calling Native From Java

    Now that you have written the native code, let’s switch back over to Java. In the default Activity, create a button and add a button handler however you want. From within your button handler, make the call to helloLog:
    1. helloLog("This will log to LogCat via the native call.");
    Then you have to add the function declaration on the Java side. Add the following declaration to your Activity class:
    1. private native void helloLog(String logThis);
    This tells the compilation and linking system that the implementation for this method will be from the native code.
    Finally, you need to load the library that the native code will ultimately compile to. Add the following static initializer to the Activity class to load the library by name (the library name itself is up to you, and will be referenced again in the next step):

    1. static {
    2. System.loadLibrary("ndk1");
    3. }

    Step 5: Adding the Native Code Make File

    Within the jni folder, you now need to add the makefile that will be used during compilation. This file must be named “Android.mk” and if you named your file native.c and your library ndk1, then the Android.mk contents will look like this:
    1. LOCAL_PATH := $(call my-dir)

    2. include $(CLEAR_VARS)

    3. LOCAL_LDLIBS := -llog

    4. LOCAL_MODULE := ndk1
    5. LOCAL_SRC_FILES := native.c

    6. include $(BUILD_SHARED_LIBRARY)

    Step 6: Compiling the Native Code

    Now that your native code is written and your make file is in place, it’s time to compile the native code. From the command line (Windows users, you’ll want to do this within Cygwin), you’ll need to run the ndk-build command from the root directory of your project. The ndk-build tool is found within the NDK tools directory. We find it easiest to add this tool to our path.
    Fig 1: Typical build output from the ndk-build command
    On subsequent compiles, you can make sure everything is recompiled if you use the “ndk-build clean” command.

    Step 7: Running the Code

    Now you’re all set to run the code. Load the project in to your favorite emulator or handset, watch LogCat, and push the button.
    One of two things may have happened. First, it may have worked. If so, congratulations! But you might want to read on, anyway. You probably got an error to LogCat saying something like, “Could not execute method of activity.” This is fine. It just means you missed a step. This is easy to do in Eclipse. Usually, Eclipse is configured to recompile automatically. What it doesn’t do is recompile and relink automatically if it doesn’t know anything has changed. And, in this case, what Eclipse doesn’t know is that you compiled the native code. So, force Eclipse to recompile by “cleaning” the project (Project->Clean from the Eclipse toolbar).

    Step 8: Adding Another Native Function

    This next function will demonstrate the ability to not only return values, but to return an object, such as a String. Add the following function to native.c:

    1. jstring Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_getString(JNIEnv * env, jobject this, jint value1, jint value2)
    2. {
    3. char *szFormat = "The sum of the two numbers is: %i";
    4. char *szResult;

    5. // add the two values
    6. jlong sum = value1+value2;

    7. // malloc room for the resulting string
    8. szResult = malloc(sizeof(szFormat) + 20);

    9. // standard sprintf
    10. sprintf(szResult, szFormat, sum);

    11. // get an object string
    12. jstring result = (*env)->NewStringUTF(env, szResult);

    13. // cleanup
    14. free(szResult);

    15. return result;
    16. }
    For this to compile, you’ll want to add an include statement as well for stdio.h. And, to correspond to this new native function, add the following declaration in your Activity Java class:
    1. private native String getString(int value1, int value2);
    You can now wire up the functionality however you like. We used the following two calls and outputs:
    1. String result = getString(5,2);
    2. Log.v(DEBUG_TAG, "Result: "+result);
    3. result = getString(1051232);
    4. Log.v(DEBUG_TAG, "Result2: "+result);
    Back to the C function, you’ll note that we did a couple things. First, we create need a buffer to write to for the sprintf() call using the malloc() function. This is reasonable so long as you don’t forget to free the results when you’re done using the free() function. Then, to pass the result back, you can use a JNI helper function called NewStringUTF(). This function basically it takes the C string and makes a new Java object out of it. This new String object can then be returned as the result and you’ll be able to use it as a regular Java String object from the Java class.
    Fig 2: Screen from sample implementation

    Instruction Sets, Compatibility, Etc.

    The Android NDK requires Android SDK 1.5 or later. In later versions of the NDK, new headers have been made available for expanded access to certain APIs—in particular, OpenGL ES libraries.
    However, that’s not the compatibility we’re talking about. This is native code, compiled to the processor architecture in use. So, one question you might be asking yourself is what processor architectures are supported? In the current NDK (as of this writing) only the ARMv5TE and ARMv7-A instruction sets are supported. By default, the target is set to ARMv5TE, which will work on all Android devices with ARM chips.
    There are plans for further instruction sets (x86 has been mentioned). This has an interesting implication: an NDK solution will not work on all devices. For instance, there are Android tablets out there that use the Intel Atom processor, which has an x86 instruction set.
    So how does the NDK work on the emulator? The emulator is running a true virtual machine, including full processor emulation. And yes, that means when running Java within the emulator you’re running a VM inside a VM.

    Conclusion

    How did you do? Did you get Android NDK installed and ultimately make a functional, running application that uses native C code as part of it? We hope so. There are many potential “gotchas!” along the way but in some cases, it can be worth the effort. As always, we’d love to hear your feedback

    viernes, 6 de abril de 2012

    How to make a phone call in Android


    In this tutorial, we show you how to make a phone call in Android,and monitor the phone call states viaPhoneStateListener.
    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:orientation="vertical" >
     
        <Button
            android:id="@+id/buttonCall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="call 0377778888" />
     
    </LinearLayout>




    2. Activity

    Use below code snippet to make a phone call in Android.
     Intent callIntent = new Intent(Intent.ACTION_CALL);
     callIntent.setData(Uri.parse("tel:0377778888"));
     startActivity(callIntent);
    File : MainActivity.java – When the button is call, make a phone to 0377778888.
    package com.mkyong.android;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
     
    public class MainActivity extends Activity {
     
     private Button button;
     
     public void onCreate(Bundle savedInstanceState) {
     
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     
      button = (Button) findViewById(R.id.buttonCall);
     
      // add button listener
      button.setOnClickListener(new OnClickListener() {
     
       @Override
       public void onClick(View arg0) {
     
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:0377778888"));
        startActivity(callIntent);
     
       }
     
      });
     
     }
     
    }




    3 Android Manifest

    To make a phone call, Android need CALL_PHONE permission.
    <uses-permission android:name="android.permission.CALL_PHONE" />
    File : AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.mkyong.android"
        android:versionCode="1"
        android:versionName="1.0" >
     
        <uses-sdk android:minSdkVersion="10" />
     
     <uses-permission android:name="android.permission.CALL_PHONE" />
     
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
     
            <activity
                android:label="@string/app_name"
                android:name=".MainActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
     
    </manifest>

    4. PhoneStateListener example

    Ok, now we update the above activity, to monitor the phone call states, when a phone call is ended, come back to the original activity (actually, it just restart the activity). Read comment, it should be self-explanatory.
    Note
    Run it and refer to the logcat console to understand how PhoneStateListener works.
    File : MainActivity.java
    package com.mkyong.android;
     
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
     
    public class MainActivity extends Activity {
     
     final Context context = this;
     private Button button;
     
     public void onCreate(Bundle savedInstanceState) {
     
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     
      button = (Button) findViewById(R.id.buttonCall);
     
      // add PhoneStateListener
      PhoneCallListener phoneListener = new PhoneCallListener();
      TelephonyManager telephonyManager = (TelephonyManager) this
       .getSystemService(Context.TELEPHONY_SERVICE);
      telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
     
      // add button listener
      button.setOnClickListener(new OnClickListener() {
     
       @Override
       public void onClick(View arg0) {
     
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:0377778888"));
        startActivity(callIntent);
     
       }
     
      });
     
     }
     
     //monitor phone call activities
     private class PhoneCallListener extends PhoneStateListener {
     
      private boolean isPhoneCalling = false;
     
      String LOG_TAG = "LOGGING 123";
     
      @Override
      public void onCallStateChanged(int state, String incomingNumber) {
     
       if (TelephonyManager.CALL_STATE_RINGING == state) {
        // phone ringing
        Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
       }
     
       if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
        // active
        Log.i(LOG_TAG, "OFFHOOK");
     
        isPhoneCalling = true;
       }
     
       if (TelephonyManager.CALL_STATE_IDLE == state) {
        // run when class initial and phone call ended, 
        // need detect flag from CALL_STATE_OFFHOOK
        Log.i(LOG_TAG, "IDLE");
     
        if (isPhoneCalling) {
     
         Log.i(LOG_TAG, "restart app");
     
         // restart app
         Intent i = getBaseContext().getPackageManager()
          .getLaunchIntentForPackage(
           getBaseContext().getPackageName());
         i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         startActivity(i);
     
         isPhoneCalling = false;
        }
     
       }
      }
     }
     
    }
    Update Android Manifest file again, PhoneStateListener need READ_PHONE_STATE permission.
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    File : AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.mkyong.android"
        android:versionCode="1"
        android:versionName="1.0" >
     
        <uses-sdk android:minSdkVersion="10" />
     
        <uses-permission android:name="android.permission.CALL_PHONE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
     
            <activity
                android:label="@string/app_name"
                android:name=".MainActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
     
    </manifest>

    5. Demo

    Activity started, just display a button.
    android phone call example
    When button is clicked, make a phone call to 0377778888.
    android phone call example
    When phone call is hang out or ended, restart the main activity.
    android phone call example

    Download Source Code

    Download it – Android-Make-Phone-Call-Example.zip (16 KB)

    References

    1. Android PhoneStateListener Javadoc
    2. Android TelephonyManager Javadoc
    3. Android Intent Javadoc

    miércoles, 4 de abril de 2012

    LinkedIn’s New Group Search: Helping you find the right conversation faster


    Every day, millions of professionals like you are talking on LinkedIn’s Groups to find opportunities, share knowledge, and learn from each other. This is why today we’re announcing some important improvements to group search.
    For example, our members have created over 1.2 million groups on LinkedIn about topics ranging from real estate to fashion to entomology. As we’ve grown, it’s become even more important for us to help you find and engage with the topics you care about most.
    Group search helps you search across all the groups on LinkedIn and find the right group for you. We’ve made several improvements to make your search results smarter and more relevant.
    First, instead of relying on the title and description of the group, we give you the best results based on how well your search matches the conversations taking place. We also show your connections who may be in that group, which makes it easier for you to find groups that really matter to you.
    Filtering your results is improved as well. You can now filter your results by your network, categories, and also language.

    Try it out by searching for groups about social mediainterview tips, or real estate.
    What conversation would you like to have?  Try the new group search today.

    How to send SMS message in 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 :
    1. SmsManager API
       SmsManager smsManager = SmsManager.getDefault();
       smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
    2. Built-in SMS application
       Intent sendIntent = new Intent(Intent.ACTION_VIEW);
       sendIntent.putExtra("sms_body", "default content"); 
       sendIntent.setType("vnd.android-dir/mms-sms");
       startActivity(sendIntent);
    Of course, both need SEND_SMS permission.
    <uses-permission android:name="android.permission.SEND_SMS" />
    P.S This project is developed in Eclipse 3.7, and tested with Samsung Galaxy S2 (Android 2.3.3).
    Note
    The Built-in SMS application solution is the easiest way, because you let device handle everything for you.

    1. SmsManager Example

    Android layout file to textboxes (phone no, sms message) and button to send the SMS message.
    File : res/layout/main.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
     
        <TextView
            android:id="@+id/textViewPhoneNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Enter Phone Number : "
            android:textAppearance="?android:attr/textAppearanceLarge" />
     
        <EditText
            android:id="@+id/editTextPhoneNo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:phoneNumber="true" >
        </EditText>
     
        <TextView
            android:id="@+id/textViewSMS"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Enter SMS Message : "
            android:textAppearance="?android:attr/textAppearanceLarge" />
     
        <EditText
            android:id="@+id/editTextSMS"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:lines="5"
            android:gravity="top" />
     
        <Button
            android:id="@+id/buttonSend"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Send" />
     
    </LinearLayout>
    File : SendSMSActivity.java – Activity to send SMS via SmsManager.
    package com.mkyong.android;
     
    import android.app.Activity;
    import android.os.Bundle;
    import android.telephony.SmsManager;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
     
    public class SendSMSActivity extends Activity {
     
     Button buttonSend;
     EditText textPhoneNo;
     EditText textSMS;
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     
      buttonSend = (Button) findViewById(R.id.buttonSend);
      textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
      textSMS = (EditText) findViewById(R.id.editTextSMS);
     
      buttonSend.setOnClickListener(new OnClickListener() {
     
       @Override
       public void onClick(View v) {
     
         String phoneNo = textPhoneNo.getText().toString();
         String sms = textSMS.getText().toString();
     
         try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, sms, null, null);
        Toast.makeText(getApplicationContext(), "SMS Sent!",
           Toast.LENGTH_LONG).show();
         } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
         "SMS faild, please try again later!",
         Toast.LENGTH_LONG).show();
        e.printStackTrace();
         }
     
       }
      });
     }
    }
    File : AndroidManifest.xml , need SEND_SMS permission.
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.mkyong.android"
        android:versionCode="1"
        android:versionName="1.0" >
     
        <uses-sdk android:minSdkVersion="10" />
     
        <uses-permission android:name="android.permission.SEND_SMS" />
     
        <application
            android:debuggable="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:label="@string/app_name"
                android:name=".SendSMSActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
     
    </manifest>
    See demo :
    send sms message via smsmanager

    2. Built-in SMS application Example

    This example is using the device’s build-in SMS application to send out the SMS message.
    File : res/layout/main.xml – A button only.
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
     
        <Button
            android:id="@+id/buttonSend"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Send" />
     
    </LinearLayout>
    File : SendSMSActivity.java – Activity class to use build-in SMS intent to send out the SMS message.
    package com.mkyong.android;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
     
    public class SendSMSActivity extends Activity {
     
     Button buttonSend;
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     
      buttonSend = (Button) findViewById(R.id.buttonSend);
     
      buttonSend.setOnClickListener(new OnClickListener() {
     
       @Override
       public void onClick(View v) {
     
        try {
     
             Intent sendIntent = new Intent(Intent.ACTION_VIEW);
             sendIntent.putExtra("sms_body", "default content"); 
             sendIntent.setType("vnd.android-dir/mms-sms");
             startActivity(sendIntent);
     
        } catch (Exception e) {
         Toast.makeText(getApplicationContext(),
          "SMS faild, please try again later!",
          Toast.LENGTH_LONG).show();
         e.printStackTrace();
        }
       }
      });
     }
    }
    See demo :
    send sms via build-in sms application
    send sms via build-in sms application