java - 调用电话按钮

标签 java android android-activity phone-call

我正在尝试向我的应用程序添加多个按钮,因此如果您单击一个按钮,您会自动调用某个人,但现在我陷入了调用操作,当单击该按钮时如何调用电话按钮?我的 Activity 有以下代码,名为 telefoonnummers.java:

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??
            }
        }
}

请大家帮忙吗???

最佳答案

将以下权限添加到您的 list 中:

<uses-permission android:name="android.permission.CALL_PHONE" />

然后在单击按钮时执行此 Intent:

String uri = "tel: phone_number_here";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);

您还可以使用 Intent.ACTION_DIAL 代替 Intent.ACTION_CALL。这显示拨号器已输入号码,但允许用户决定是否实际调用电话。 ACTION_DIAL 不需要 CALL_PHONE 权限。

关于java - 调用电话按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15185463/

相关文章:

java - Row_number() 和按 SQL 语句分区在 java 类中不起作用

java - 使用 Quartz 运行 Spring Boot 应用

android - 登录页面重定向的 Intent 标志,杀死以前的 Activity

Android 2.1 复选框组件 : change check color

Android Activity 生命终结

java - 10秒的滑动窗口?

java - Android-Stripe 在创建帐户时添加缺少的参数

c# - 在 Android 上的 Unity 中从 C++ DLL 访问 StreamingAssets 资源

android - 如何使用 onWindowFocusChanged() 方法?

android - 配置Android搜索小部件时,如果当前 Activity 不是可搜索 Activity ,该怎么办?