Tuesday, July 10, 2012

Calling Builtin Applications Using Intents



Click Here to download source code

package name  :  selva.builtin

project name    :  callingbuiltinapp

version             :  1.5  ( supports 1.5 and above versions)

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/webbrowser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Web Browser" />
<Button
android:id="@+id/makecalls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Make Calls" />

</LinearLayout>



 CallingbuiltinappActivity.java



package selva.builtin;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
       
        public class CallingbuiltinappActivity extends Activity {
        Button b1, b2;
        int request_Code = 1;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //---Web browser button---
       
        b1 = (Button) findViewById(R.id.webbrowser);
        b1.setOnClickListener(new OnClickListener()
        {
        public void onClick(View arg0){
        Intent i = new
        Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("http://www.google.com"));
        startActivity(i);
        }
        });
        //---Make calls button---
        b2 = (Button) findViewById(R.id.makecalls);
        b2.setOnClickListener(new OnClickListener()
        {
        public void onClick(View arg0){
        Intent i = new
        Intent(android.content.Intent.ACTION_DIAL,
        Uri.parse("tel:+919750376373"));
        startActivity(i);
        }
        });
     
   
        }
        public void onActivityResult(int requestCode, int resultCode, Intent data)
        {
        if (requestCode == request_Code)
        {
        if (resultCode == RESULT_OK)
        {
            Toast.makeText(this,data.getData().toString(),
                    Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(
                    android.content.Intent.ACTION_VIEW,
                    Uri.parse(data.getData().toString()));
                    startActivity(i);
                    }
                    }
                    }
   
    }



OUTPUT:
























click web Browser button

















































click make calls button



























Click Here to download source code



No comments:

Post a Comment