2009年6月26日金曜日

Android  - Intent を使う -

・ブラウザを開く

  1. Intent bi = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));  
  2. startActivity(bi);  




・ダイアル画面を表示する

  1. Intent di = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:123456789"));  
  2. startActivity(di);  





・Google Maps を表示する (Builed Target が Google APIs でないとダメ)

  1. Intent mi = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=Tokyo"));  
  2. startActivity(mi);  





・コンタクトリストを表示する

  1. Intent cti = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/1"));  
  2. startActivity(cti);  





More...


  1. package org.example.hello;  
  2.   
  3. import android.app.Activity;  
  4. import android.net.Uri;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.widget.Button;  
  9. import android.content.Intent;  
  10.   
  11. public class Hello extends Activity implements OnClickListener{  
  12.     /** Called when the activity is first created. */  
  13.     @Override  
  14.     public void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.main);  
  17.   
  18.         View browserTestButton = this.findViewById(R.id.browsertest_button);  
  19.         browserTestButton.setOnClickListener(this);  
  20.         View googlemapTestButton = this.findViewById(R.id.googlemaptest_button);  
  21.         googlemapTestButton.setOnClickListener(this);  
  22.   
  23.         Button dialButton = (Button)findViewById(R.id.dialtest_button);  
  24.         dialButton.setOnClickListener(this);  
  25.         Button contactButton = (Button)findViewById(R.id.contacttest_button);  
  26.         contactButton.setOnClickListener(this);  
  27.         Button closeButton = (Button)findViewById(R.id.close_button);  
  28.         closeButton.setOnClickListener(this);  
  29.     }  
  30.   
  31.     public void onClick(View v) {  
  32.      switch(v.getId()){  
  33.      case R.id.browsertest_button:  
  34.       Intent bi = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));  
  35.       startActivity(bi);  
  36.       break;  
  37.      case R.id.googlemaptest_button:  
  38.       Intent mi = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=Tokyo"));  
  39.       startActivity(mi);  
  40.       break;  
  41.      case R.id.dialtest_button:  
  42.       Intent di = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:123456789"));  
  43.       startActivity(di);  
  44.       break;  
  45.      case R.id.contacttest_button:  
  46.       Intent cti = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/1"));  
  47.       startActivity(cti);  
  48.       break;  
  49.      case R.id.close_button:  
  50.       finish();  
  51.      }  
  52.     }      
  53. }  


コンタクトリストを登録しておく



0 件のコメント:

コメントを投稿