Intent newActivity = new Intent(Intent.ACTION_CALL); newActivity.setData(Uri.parse("tel:0819876107")); startActivity(newActivity);
<uses-permission android:name="android.permission.CALL_PHONE" />
<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" > <Button android:id="@+id/btnCall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="42dp" android:text="Call 0819876107" /> </RelativeLayout>
package com.myapp; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.content.Intent; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnCall = (Button) findViewById(R.id.btnCall); btnCall.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newActivity = new Intent(Intent.ACTION_CALL); newActivity.setData(Uri.parse("tel:0819876107")); startActivity(newActivity); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท