简体   繁体   English

如何从Java应用程序拨打语音电话? 如何使该程序正常工作?

[英]How do I make a voice call from my Java app? How do I make this program work?

I am trying to make a call to a number, or any random voice service because it does not have to be functional as this is a school project. 我正在尝试拨打电话号码或任何随机语音服务,因为它不是必须的功能,因为这是一个学校项目。 Here is the code for my jframe. 这是我的jframe的代码。

What I want to do is, when I click the call icon, it calls the number or a voice program. 我想做的是,当我单击呼叫图标时,它会呼叫该号码或语音程序。

public class Counselling extends JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Counselling frame = new Counselling();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Counselling() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 510, 450);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JButton btnNewButton = new JButton("");
        Image images = new ImageIcon(this.getClass().getResource("/call.png")).getImage();
        btnNewButton.setIcon(new ImageIcon(images));
        btnNewButton.setBounds(106, 92, 268, 133);
        contentPane.add(btnNewButton);


        JButton button = new JButton("");
        button.setBackground(Color.WHITE);
        Image images2 = new ImageIcon(this.getClass().getResource("/msg.png")).getImage();
        button.setIcon(new ImageIcon(images2));
        button.setBounds(106, 241, 268, 125);
        contentPane.add(button);



        JLabel lblNewLabel_1 = new JLabel("");
        Image images1 = new ImageIcon(this.getClass().getResource("/oc.png")).getImage();
        lblNewLabel_1.setIcon(new ImageIcon(images1));
        lblNewLabel_1.setBounds(38, 16, 435, 60);
        contentPane.add(lblNewLabel_1);
    }
}

Twilio is the most common service out there and is extremely affordable. Twilio是那里最常见的服务,而且价格实惠。 If you are using Maven, install by adding it to your pom.xml file: 如果使用的是Maven,请通过将其添加到pom.xml文件进行安装:

<dependency>
    <groupId>com.twilio.sdk</groupId>
    <artifactId>twilio-java-sdk</artifactId>
    <version>3.4.5</version>
</dependency>

Here is some example code on how you would place a phone call: 这是一些有关如何拨打电话的示例代码:

import java.util.Map;
import java.util.HashMap;

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.factory.CallFactory;

public class MakeCall {

    public static final String ACCOUNT_SID = "AC123";
    public static final String AUTH_TOKEN = "456bef";

    public static void main(String[] args) throws TwilioRestException {

        TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID,     AUTH_TOKEN);
        Account mainAccount = client.getAccount();
        CallFactory callFactory = mainAccount.getCallFactory();
        Map<String, String> callParams = new HashMap<String, String>();
        callParams.put("To", "5105551212"); // Replace with your phone number
        callParams.put("From", "(510) 555-1212"); // Replace with a Twilio number
        callParams.put("Url", "http://demo.twilio.com/welcome/voice/");
        // Make the call
        Call call = callFactory.create(callParams);
        // Print the call SID (a 32 digit hex like CA123..)
        System.out.println(call.getSid());
    }
}

Check out the Twilio install guide for java for more information: 请查看《 Twilio Java安装指南》以获取更多信息:

https://www.twilio.com/docs/java/install https://www.twilio.com/docs/java/install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM