Android 撥號器的簡單實現,android撥號器實現

來源:互聯網
上載者:User

Android 撥號器的簡單實現,android撥號器實現

功能實現:一個EditView 一個撥打按鈕,輸入號碼跳轉到撥號介面

介面布局:activity_call.xml

  //線性垂直布局:一個EditView文本、一個Button按鈕
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin"10 tools:context=".PhoneActivity" >11 12 <TextView13 android:layout_width="wrap_content"14 android:layout_height="wrap_content"15 android:text="請輸入電話" />16 17 <EditText18 android:id="@+id/editText1"19 android:layout_width="fill_parent"20 android:layout_height="wrap_content"21 android:inputType="phone" />22 23 <Button24 android:id="@+id/callsumbit"25 android:layout_width="wrap_content"26 android:layout_height="wrap_content"27 android:layout_gravity="center"28 android:text="撥打到電話" />29 30 </LinearLayout>

CallActivity的Create方法

 1 protected void onCreate(Bundle savedInstanceState) { 2         super.onCreate(savedInstanceState); 3         setContentView(R.layout.activity_call); 4         Button btn = (Button) findViewById(R.id.callsumbit); 5         btn.setOnClickListener(new OnClickListener() { 6  7             @Override 8             public void onClick(View v) { 9                 EditText etNumber = (EditText) findViewById(R.id.editText1);10 11                 String number = etNumber.getText().toString();12                 Intent intent = new Intent();13                 intent.setAction(Intent.ACTION_CALL);14                 intent.setData(Uri.parse("tel:" + number));15                 startActivity(intent);16             }17         });18     }

增加撥打到電話的許可權:AndroidManifest.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3     package="com.ccec.callphone" 4     android:versionCode="1" 5     android:versionName="1.0" > 6  7     <uses-sdk 8         android:minSdkVersion="8" 9         android:targetSdkVersion="18" />10     <uses-permission android:name="android.permission.CALL_PHONE"/>11 12     <application13         android:allowBackup="true"14         android:icon="@drawable/ic_launcher"15         android:label="@string/app_name"16         android:theme="@style/AppTheme" >17         <activity18             android:name="com.ccec.callphone.CallActivity"19             android:label="@string/app_name" >20             <intent-filter>21                 <action android:name="android.intent.action.MAIN" />22 23                 <category android:name="android.intent.category.LAUNCHER" />24             </intent-filter>25         </activity>26     </application>27 28 </manifest>

至此可以實現撥號功能。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.