Monday, April 9, 2012

Call and Sms in Android

CALL
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse("tel:5556"));
startActivity(i);

permission
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

SMS

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("sms:5556")); 
startActivity(intent);

permission
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>


 Web Browsing



Uri address=Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW,address); 
startActivity(intent);


----------------------------------------------------------------------------------------------------------------------------
Example:-

package c.s;

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 CallsmsActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

Button call,sms,browse;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        call=(Button) findViewById(R.id.call);
        call.setOnClickListener(this);
     
        sms=(Button) findViewById(R.id.sms);
        sms.setOnClickListener(this);
     
        browse=(Button) findViewById(R.id.browse);
        browse.setOnClickListener(this);
     
    }


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==call)
{

Intent i=new Intent(Intent.ACTION_CALL,Uri.parse("tel:5556"));
             startActivity(i);
}

if(v==sms)
{
 Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("sms:5556")); 
     startActivity(intent);
}

if(v==browse)
{
 Uri address=Uri.parse("http://www.google.com");
 Intent intent = new Intent(Intent.ACTION_VIEW,address); 
     startActivity(intent);
}
}
}


---------------------------------------------------------------------------------------------------
xml:-



<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button android:text="Call"
 android:id="@+id/call"
 android:layout_height="wrap_content"
 android:layout_width="74dp"
 android:layout_x="119dp"
 android:layout_y="164dp">
 </Button>
 
 <Button android:layout_width="63dp"
 android:text="Sms"
 android:layout_height="wrap_content"
 android:id="@+id/sms"
 android:layout_x="126dp"
 android:layout_y="230dp">
 </Button>

<Button android:layout_width="wrap_content"
android:text="Browse"
android:layout_height="wrap_content"
android:id="@+id/browse"
android:layout_x="125dp"
android:layout_y="294dp">
</Button>


</AbsoluteLayout>

----------------------------------------------------------------------------------------------------




No comments :

Post a Comment