溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Android實(shí)現(xiàn)撥號(hào)器電話

發(fā)布時(shí)間:2020-07-09 01:37:37 來(lái)源:網(wǎng)絡(luò) 閱讀:572 作者:Java大白 欄目:移動(dòng)開(kāi)發(fā)

xml中的代碼實(shí)現(xiàn)

<RelativeLayout 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:padding="20dp"
 >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title" />
   <EditText 
       android:id="@+id/phonenumber"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="請(qǐng)輸入手機(jī)號(hào)碼"
       android:inputType="phone"
       android:layout_below="@id/title"
       
       />
	<Button 
	    android:id="@+id/but"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:onClick="call"
	    android:text="撥打"
	    android:layout_below="@id/phonenumber"
	    />
</RelativeLayout>

mainActivity中代碼的實(shí)現(xiàn)

public class MainActivity extends Activity {
	private EditText edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edit=(EditText)findViewById(R.id.phonenumber);
    }

	public  void call(View v){
	System.out.println("被點(diǎn)擊了");
	String num=edit.getText().toString();
	 
	Intent intent=new Intent();//創(chuàng)建一個(gè)意圖
	intent.setAction(intent.ACTION_CALL);//指定動(dòng)作為撥打電話
	intent.setData(Uri.parse("tel:"+num));//指定要播出的電話號(hào)碼
	startActivity(intent);
	
	}
  
}

同時(shí)還需要給我們的應(yīng)用程序添加一個(gè)可以撥打號(hào)碼的權(quán)限

<!-- 添加撥打電話的權(quán)限 -->
	<uses-permission 
	    android:name="android.permission.CALL_PHONE"
	    />


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI