android 调用手机打电话

醉酒当歌 提交于 2019-11-25 21:58:30

android 调用手机打电话

<uses-permission android:name="android.permission.CALL_PHONE"/>电话权限

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".call.CallphoneActivity">
<Button
    android:id="@+id/btn"
    android:text="打电话"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" />
 
</LinearLayout>


public class CallphoneActivity extends AppCompatActivity {
Button btn;
String ss= "123456789";
//<uses-permission android:name="android.permission.CALL_PHONE"/>电话权限
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_callphone);
        btn=findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //创建打电话的意图
                            Intent intent = new Intent();
                              //设置拨打电话的动作
                              intent.setAction(Intent.ACTION_CALL);
                           //设置拨打电话的号码
                               intent.setData(Uri.parse("tel:" + ss));
                              //开启打电话的意图
                            startActivity(intent);
            }
        });
    }
}
 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!