CallPhone01.java
package com.ststudy.Call;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* Created by aaron on 9/1/15.
*/
public class CallPhone01 extends Activity {
private EditText mEtPhoneNumber = null;
private Button mBtCall = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// this.getWindow().setContentView(this.getLayoutInflater().inflate(R.layout.activity_main, null));
findId();
listen();
}
private void findId()
{
mEtPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
mBtCall = (Button) findViewById(R.id.btCall);
}
private void listen()
{
mBtCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String _phoneNumber = null;
_phoneNumber = mEtPhoneNumber.getText().toString();
Intent _intent = new Intent();
_intent.setAction(Intent.ACTION_CALL);
_intent.setData(Uri.parse("tel:" + _phoneNumber));
// Toast.makeText(CallPhone01.this,_phoneNumber,Toast.LENGTH_SHORT).show();
startActivity(_intent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/etPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="请输入号码"/>
<Button
android:id="@+id/btCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="拨打电话"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ststudy.Call">
<uses-sdk android:minSdkVersion="13"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!--打电话的主Acticity-->
<activity android:name=".CallPhone01">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<!-- 打电话的权限-->
<uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>
效果图: