溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android實現撥號器電話

發布時間:2020-07-09 01:37:37 來源:網絡 閱讀:578 作者:Java大白 欄目:移動開發

xml中的代碼實現

<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="請輸入手機號碼"
       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中代碼的實現

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("被點擊了");
	String num=edit.getText().toString();
	 
	Intent intent=new Intent();//創建一個意圖
	intent.setAction(intent.ACTION_CALL);//指定動作為撥打電話
	intent.setData(Uri.parse("tel:"+num));//指定要播出的電話號碼
	startActivity(intent);
	
	}
  
}

同時還需要給我們的應用程序添加一個可以撥打號碼的權限

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


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女