Android系統的組件的通信

intent類 主要包括component  action  data  category  extras  flags

 intentfilter 對象負責過濾掉無法響應和處理的intent 只將自己關心的intent 接受進來處理

一個intent想要被一個組件處理,必須通過三個環節檢查: 檢查action  檢查data  檢查category

下面是我應用的一個程序:

調用系統的撥號程序

java代碼

package jm.out;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
//繼承自Activity的子類
public class DialconnectActivity extends Activity {
 Button btnDial;
    @Override
    public void onCreate(Bundle savedInstanceState) {//重寫onCreate方法
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);//設置屏幕顯示內容
        btnDial = (Button)this.findViewById(R.id.btDial);//獲得屏幕上按鈕對象引用
        btnDial.setOnClickListener(new Button.OnClickListener(){//爲按鈕添加點擊事件的監聽器
   @Override
   public void onClick(View v) {//重寫onClick方法
    Intent myIntent = new Intent(Intent.ACTION_DIAL);//創建Intent對象
    DialconnectActivity.this.startActivity(myIntent);//啓動Android內置的撥號程序
   }         
        });
    }
}

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/btDial"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="撥號" />
</LinearLayout>
運行的效果:

上面是調用的界面:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章