Using Intent to make another phone call : Intent « Core Class « Android






Using Intent to make another phone call

    

package app.test;

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.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;

class MyBrowserActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.row);
    Uri url = getIntent().getData();
    WebView webView = (WebView) findViewById(R.id.WebView01);
    webView.setWebViewClient(new Callback());
    webView.loadUrl(url.toString());
  }
  private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      return (false);
    }
  }
}
public class Test extends Activity {

  Button b1, b2, b3, b4, b5;
  int request_Code = 1;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b1 = (Button) findViewById(R.id.btn_webbrowser);
    b1.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent i = new Intent("android.intent.action.VIEW");
        i.setData(Uri.parse("http://www.amazon.com"));
        startActivity(i);
      }
    });
    b2 = (Button) findViewById(R.id.btn_makecalls);
    b2.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent i = new Intent(android.content.Intent.ACTION_CALL, Uri.parse("tel:+651234567"));
        startActivity(i);
      }
    });
    b3 = (Button) findViewById(R.id.btn_showMap);
    b3.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri
            .parse("geo:37.827500,-122.481670"));
        startActivity(i);
      }
    });
    b4 = (Button) findViewById(R.id.btn_chooseContact);
    b4.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent i = new Intent(android.content.Intent.ACTION_PICK);
        i.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        startActivityForResult(i, request_Code);
      }
    });

    b5 = (Button) findViewById(R.id.btn_launchMyBrowser);
    b5.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent i = new Intent("app.test.MyBrowser", Uri
            .parse("http://www.amazon.com"));
        i.addCategory("app.test.OtherApps");
        i.addCategory("app.test.SomeOtherApps");
        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);
      }
    }
  }
}

//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/btn_webbrowser"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Web Browser" />    
<Button
    android:id="@+id/btn_makecalls"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Make Calls" />   
<Button
    android:id="@+id/btn_showMap"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Show Map" />    
<Button
    android:id="@+id/btn_chooseContact"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Choose Contact" />
<Button
    android:id="@+id/btn_launchMyBrowser"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Launch My Browser" />
    
</LinearLayout>
//row.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" >
<WebView 
    android:id="@+id/WebView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />
</LinearLayout>

   
    
    
    
  








Related examples in the same category

1.Using Intent to open other Activity
2.Create Intent to open a Uri
3.extends IntentService
4.Phone Intent
5.Map Intent
6.Market Intent
7.Load Activity with Intent
8.extends IntentService to create your own Intent
9.Adding data bundle to Intent
10.Using Intent to show other Activities
11.Start Intent with Utility class
12.Load library Activity with Intent
13.Capture Image with Intent
14.Intent.ACTION_MEDIA_MOUNTED
15.Using Intent to record audio
16.Video Player Intent
17.Video Capture Intent
18.Implementing an application service that will run in response to an alarm, allowing us to move long duration work out of an intent receiver.
19.Example of various Intent flags to modify the activity stack.
20.Sample code that invokes the speech recognition intent API.
21.extends IntentService to upload a file
22.factory class for generating various intents
23.Open Web Page Intent
24.Is Intent Available
25.start MMS Intent
26.Access the Internet
27.Pdf viewer
28.Rotation One Demo
29.Media activity