青玄 发表于 2014-11-4 21:53:27

[原创]简单的电话拨号器

1.拨号器所需要的权限的配置
<uses-permission android:name="android.permission.CALL_PHONE"/>2.拨号器布局的配置:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <EditText
      android:id="@+id/phone"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="输入电话号码"
      android:inputType="number"
      />
    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="拨号"
      android:onClick="call"
      />

</LinearLayout>如图:


3.在activity中编写拨号程序:

package com.example.callphone_test;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

        private EditText phoneText;
       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
               
                phoneText = (EditText) this.findViewById(R.id.phone);
        }
       
        public void call(View v)
        {
                String number = phoneText.getText().toString().trim();
                //打开系统呼叫
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);   //与系统拨号中的action进行匹配
                intent.setData(Uri.parse("tel://" + number));//设置拨号的Uri
                startActivity(intent);//跳转到系统的拨号器上面
        }
}


















传说。 发表于 2014-11-7 19:19:54

JAVA新手路过。只看懂了importpublic刚学没多久。

青玄 发表于 2014-11-7 20:01:42

传说。 发表于 2014-11-7 19:19
JAVA新手路过。只看懂了importpublic刚学没多久。

呵呵!不急!慢慢来~{:7_139:}
页: [1]
查看完整版本: [原创]简单的电话拨号器