Java 按呼叫按钮
我正在尝试向我的应用程序中添加多个按钮,因此如果你单击其中一个按钮,你会自动呼叫某个人,但现在我被困在呼叫操作中,当有人单击按钮时,我如何拨打电话?我的活动名为telefoonnumers.java,代码如下:Java 按呼叫按钮,java,android,android-activity,phone-call,Java,Android,Android Activity,Phone Call,我正在尝试向我的应用程序中添加多个按钮,因此如果你单击其中一个按钮,你会自动呼叫某个人,但现在我被困在呼叫操作中,当有人单击按钮时,我如何拨打电话?我的活动名为telefoonnumers.java,代码如下: package com.example.rome; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import
package com.example.rome;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.widget.EditText;
import android.widget.Button;
import android.view.View;
import android.widget.Toast;
public class Telefoonnummers extends Activity {
Button mHALbellen;
Button mWITbellen;
Button mWDGbellen;
Button mVlierbellen;
Button mHotelbellen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_telefoonnummers);
mHALbellen = (Button) findViewById(R.id.button1);
mWITbellen = (Button) findViewById(R.id.button3);
mWDGbellen = (Button) findViewById(R.id.button4);
mVlierbellen = (Button) findViewById(R.id.button5);
mHotelbellen = (Button) findViewById(R.id.button6);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_telefoonnummers, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void vanHalbellen(View view){
if (view == mHALbellen){
//WHICH CODE SHOULD BE HERE TO MAKE A PHONECALL WHEN THE BUTTON mHALBELLEN IS PRESSED??
}
}
}
请大家帮忙好吗?将以下权限添加到您的清单中:
<uses-permission android:name="android.permission.CALL_PHONE" />
您也可以使用
Intent.ACTION\u DIAL
而不是Intent.ACTION\u CALL
。这将显示已输入号码的拨号器,但允许用户决定是否实际拨打电话<代码>操作拨号不需要呼叫电话权限。将以下权限添加到您的清单中:
<uses-permission android:name="android.permission.CALL_PHONE" />
您也可以使用Intent.ACTION\u DIAL
而不是Intent.ACTION\u CALL
。这将显示已输入号码的拨号器,但允许用户决定是否实际拨打电话<代码>操作拨号不需要呼叫电话
权限