Android 拨号器 源代码
Android 拨号器 源代码
操作方法
- 01
AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.itcast.activity" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".PhoneActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.CALL_PHONE" /> </manifest>
- 02
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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/mobile" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/button" /> </LinearLayout>
- 03
PhoneActivity: import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class PhoneActivity extends Activity { // 文本框 private EditText mobileText; //按钮 private Button button; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 获取文本框 mobileText = (EditText) this.findViewById(R.id.mobile); //获取按钮 button = (Button)this.findViewById(R.id.button); //添加单击事件 button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { //获取电话号码 String mobile = mobileText.getText().toString(); //意图对象 1.意图的动作用指明交给的那一个应用 2.传输数据 Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobile)); //把意图传播给操作系统 PhoneActivity.this.startActivity(intent); } }); } }