private static final String MyTag = "CallActivity";
private EditText etPhoneNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
etPhoneNumber = (EditText) this.findViewById(R.id.et_phonenumber);
final Button btnCall = (Button) this.findViewById(R.id.bt_call);
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tempNo = etPhoneNumber.getText().toString();
Intent myIntent = new Intent(CallActivity.this,CallActivity.class);
myIntent.setAction(Intent.ACTION_DIAL);
myIntent.setData(Uri.parse("tel:"+tempNo));
startActivity(myIntent);
}
});
}
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ecarechina.phonecall.CallActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
点击按钮时,窗体有个闪动就又回到 Activity了
我的模拟器里面也没有 系统带的 打电话那个图标。
------解决方案--------------------
????????????public?void?onClick(View?v)?{?
????????????????String?tempNo?=?etPhoneNumber.getText().toString();
????Intent myIntent = new Intent(Intent.ACTION_CALL,
???? Uri.parse("tel://" + tempNo));
????startActivity(myIntent);
????????????}
onClick这么写,你那样写是不对的。