import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Example extends Activity {
/** Called when the activity is first created. */
Button b1,b2,b3,b4;
int requestcode=1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new 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.google.com"));
startActivity(i);
}
});
b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1=new Intent(android.content.Intent.ACTION_DIAL,Uri.parse("tel:+8095880668"));
startActivity(i1);
}
});
b3=(Button)findViewById(R.id.button3);
b3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i2 = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("geo:37.827500,-122.481670"));
startActivity(i2);
}
});
b4=(Button)findViewById(R.id.button4);
b4.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i3=new Intent(android.content.Intent.ACTION_PICK);
i3.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(i3,requestcode);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == requestcode)
{
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);
}
}
}
}
No comments:
Post a Comment