Archive Pages Design$type=blogging

How to call built-in applications using intents in Android

In this tutorial for developing android apps we will learn how to call built-in applications using intents

Developing android apps specially the games required opengl for providing better graphics. We have seen how to get started with opengl es for android, and will continue the opengl tutorial  for android programming. Today's we are going to learn an important concept in this android development tutorial, how to call built-in applications using intents in Android. This give advantage to developer taking in-build apps and throw user to them if required. Calling built in applications using intents in Android is important as it give user more choices. For example in an app you want user make a call or open a document (pdf) let you use the in-build apps, take off the burden in developing those apps. You might have seen in previous Whatsapp, which let user call from within the app (now they have their own voip).

Android intent example

Lets get started with how to use intent in android. The following Try It Out demonstrates how to call some of the built-in applications commonly found on an Android device. 

Prerequisite

In this android intent example you need the Android Studio or Eclipse with ADT plugin and Android SDK tool. It is also necessary that you must know about some fundamentals of Java and XML as well as about the Android device. We also assume here that you know hello world program for developing android apps. This is a simple beginners tutorial, which hardly take you half an hour to understand, and doing yourself. I am doing this in Android Studio but you may choose Eclipse (remember google officially going to end support for ADT at the end of 2015).

Creating New Project

1. First step : Open Android Studio and Create a new project by selecting 'Start a new Android Studio Project'. Give it a name MyIntent and a package name in.ruks. You can have your own application package names. Click next, choose minimum SDK, in ours case it is API 14 : Android 4.0 (IceCreamSandwich), which accounts for close to 90% of activated android devices. Again click next, select the Blank Activity, Click next. Android will ask to name the activity, keep the default names, click on finish. Android Studio will create the the new Android Project with all the necessary files.

how to create new project in android studio for developing android apps

Set up Project Layout

We are going to use 6 built-in application in this android development tutorial. They are -
  1. Gallery
  2. Call Log
  3. Contact
  4. Dailler
  5. Browser
  6. Map
2. Second step : Now the time to set up the layout of our project. We are going to call 6 built-in applications using intents, hence we will place a button for each in activity_main.xml. You can drag and drop 6 button on the layout or simply create by coding the activity_main.xml file. Check out the code below and add it to activity_main.xml


    <button android:id="@+id/button_contacts" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/contacts">
    
<   button android:id="@+id/button_gallery" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/gallery">

<button android:id="@+id/button_Dail" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/dial">
    
    
    





3. Third step :  It's bad idea to have the hard coded string in the project. So in this android intent example code, we are given name to each of the button within the strings.xml, which is under the values folder in Android Studio. Add the code below in it -

    MyIntent
    Hello world!
    Settings
    Contacts
    Gallery
    Call a number
    Open Call Logs
    Open Browser
    Open Map
    Exit


Now we have our layout design for this android intent example, we are going to code the java file to call built-in applications using intents.

Creating  event handler

4. Fourth step : In our MainActivity.java file, we are going to declare the button for each of the Button we have created in our layout file.

Button Gallery = (Button) findViewById(R.id.button_gallery);
Button CallLog = (Button) findViewById(R.id.button_calllog);
Button Contacts = (Button) findViewById(R.id.button_contacts);
Button Map = (Button) findViewById(R.id.button_map);
Button Dail = (Button) findViewById(R.id.button_Dail);
Button Broswer = (Button) findViewById(R.id.button_browser);
5. Fifth step : Our Buttons are ready to have some action, now its time to attach the event handler to them. One by one we are going to call setOnClickListener method on each of our Button and call built-in applications. Just place the following code in MainActivity.java
package in.ruks.myintent;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button Gallery = (Button) findViewById(R.id.button_gallery);
        Button CallLog = (Button) findViewById(R.id.button_calllog);
        Button Contacts = (Button) findViewById(R.id.button_contacts);
        Button Map = (Button) findViewById(R.id.button_map);
        Button Dail = (Button) findViewById(R.id.button_Dail);
        Button Broswer = (Button) findViewById(R.id.button_browser);

        Contacts.setOnClickListener(new Button.OnClickListener(){

            @SuppressWarnings("deprecation")
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);
                myIntent.setData(android.provider.Contacts.People.CONTENT_URI);
                startActivity(myIntent);

            }
        });

        Gallery.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);
                myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                startActivity(myIntent);

            }
        });
        Dail.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

    /*Intent myIntent = new Intent();

    myIntent.setAction(Intent.ACTION_VIEW);
    myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    startActivity(myIntent);*/

                Intent i = new Intent(android.content.Intent.ACTION_DIAL,
                        Uri.parse("tel:+918147656011"));
                startActivity(i);
            }
        });
        CallLog.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_CALL_BUTTON);
                startActivity(myIntent);
            }
        });

        Broswer.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent i = new Intent(android.content.Intent.ACTION_VIEW,
                        Uri.parse("http://www.openglprojects.in"));
                startActivity(i);
            }
        });

        Map.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myIntent = new Intent();

                myIntent.setAction(Intent.ACTION_VIEW);
                myIntent.setData(Uri.parse("geo:37.827500,-122.481670"));
                startActivity(myIntent);

            }
        });



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        //return super.onOptionsItemSelected(item);
        if(item.getItemId()==R.id.action_exit){
            this.finish();
            return true;
        }
        return false;
    }


}

Declare Activity in  AndroidManifest

6. Final step : If you have basic knowledge of developing android apps then you must know that, every activity you have in your application must be declared in your AndroidManifest.xml file. So Know place the following code in AndroidManifest.xml file.


    
        
            
                

                
            
        
    



We finished with out coding session, time to see our work in action. Go to Run menu(alt+u) click Run App or directly run the  program with shift +F10.

Check out the demo video -

Final Thoughts

In this how to call built-in applications using intents tutorial, we have call only 6 in build apps, while you can call others as well. You can replace the mobile number with our own in android intent example activity replacing the tel:+918147656011. Same can be done with website url and map Lat Long values by replacing http://www.openglprojects.in and geo:37.827500,-122.481670 respectively in MainActivity.java file. 

Hope you liked this android development tutorial, feel free to ask anything via comments. We assume that this small step will help you in developing android apps.

COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: How to call built-in applications using intents in Android
How to call built-in applications using intents in Android
In this tutorial for developing android apps we will learn how to call built-in applications using intents
https://4.bp.blogspot.com/-eDHpbeZDL9E/VZTjCr5zLOI/AAAAAAAAHVg/UrP1WrU9bFA/s400/output_kgN3mb%2B%25281%2529.gif
https://4.bp.blogspot.com/-eDHpbeZDL9E/VZTjCr5zLOI/AAAAAAAAHVg/UrP1WrU9bFA/s72-c/output_kgN3mb%2B%25281%2529.gif
OpenGL Projects
http://www.openglprojects.in/2015/06/how-to-call-built-in-applications-using-intents-in-android.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2015/06/how-to-call-built-in-applications-using-intents-in-android.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago