Pages

Search Tutorials

Sunday, 29 September 2013

Access call, dialer screen, camera and web pages in Android

In this application we will learn how to access phone services using our activity. Implicit Intent is used to access all services which come with android phone. First we will learn what is Intent and than what is Implicit Intent?

Intent: Intent is an android service that gives us the facilities of accessing one activity from the other activity. Basically, There are two types of Intent:-

Now open your Java file and initialize all objects. Use the following tricks in implicit Intent:

Intent obj=new Intent(What to do, with whom to do);

URI (uniform resource identifier) is used to identify universal values. The code of android Java file is given below with explanation:-

package sel.impli;//your package nameimportandroid.net.Uri;importandroid.os.Bundle;importandroid.app.Activity;importandroid.content.Intent;importandroid.view.View;publicclassMainActivityextends Activity {@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}//This method is called when we click on any button//and it is declare in main XML file in button tag//we have to pass View object in this method//view object has the id of button which is clickedpublicvoidcall(View v){
Intent i=null;//get id from the view object and//perform action according to button idswitch(v.getId()){case R.id.internet://if id is internet than open net//use action view because we want to view the given website page
i=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.innosen.blogspot.com"));
startActivity(i);break;case R.id.fb://if id is fb than open facebook//use action view because we want to view the given website page
i=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com"));
startActivity(i);break;case R.id.phone://if id is phone than open phone dialer//use action dial because we want to open phone dialer
i=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:8527801400"));
startActivity(i);break;case R.id.bigb://if id is bigb than call this no. +918527801400//use action call because we want to call on the given no.
i=new Intent(Intent.ACTION_CALL, Uri.parse("tel:+918527801400"));
startActivity(i);break;case R.id.cam://if id is cam than use camera driver path to open camera
i=new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(i);break;}}}

All work finished but we are using other application services so we have to take permission to use services. So, open your AndroidManifest.xml file and add all required permission like below code: