简体   繁体   English

是否有可用于拨打电话的API?

[英]Is there any API which can be used to make phone calls?

I need to create an application for android phone to make calls with/without user interaction. 我需要为Android手机创建一个应用程序,以通过/不通过用户互动进行通话。 I learned from net and Stack Overflow ( how to make a call, without using intent ) that it can not be done. 我从net和Stack Overflow( 如何在不使用intent的情况下进行调用 )中了解到无法完成此操作。

But now, I want to know if there is some API which I can use to develop a website, which I'll launch from the Android phone, and the web service will make calls. 但是现在,我想知道是否有一些API可以用来开发网站,我将从Android手机启动该网站,然后网络服务会进行呼叫。

I have no background of web development. 我没有网络开发背景。 So, I want to confirm that is this possible? 因此,我想确认是否可能? ie is this possible that I provide the website phone number and it makes a call and the bill goes to the provided number (same as one calls from his/her phone and bill goes to his/her number. But now I don't want the Android's application to make call. I want my own web application or some Java application to make calls), I don't want to use some other service provider. 也就是说,是否有可能我提供网站电话号码并拨打电话,账单转到提供的号码(就像从他/她的电话打来的电话,账单转到他/她的电话号码一样。但是现在我不想Android应用程序进行呼叫。我希望自己的Web应用程序或Java应用程序进行呼叫),但我不想使用其他服务提供商。

If your service is going to be part of you application then you are making it way more complex than it needs to be. 如果您的服务将成为您应用程序的一部分,那么您会使它变得比所需的更加复杂。 Since you have a simple use case of getting some data from a RESTful Web Service, you should look into ResultReceiver and IntentService. 由于您有一个从RESTful Web服务获取一些数据的简单用例,因此应研究ResultReceiver和IntentService。

This Service + ResultReceiver pattern works by starting or binding to the service with startService() when you want to do some action. 当您要执行某些操作时,此Service + ResultReceiver模式通过使用startService()启动或绑定到该服务来工作。 You can specify the operation to perform and pass in your ResultReceiver (the activity) through the extras in the Intent. 您可以指定要执行的操作,并通过Intent中的其他函数传入ResultReceiver(活动)。

In the service you implement onHandleIntent to do the operation that is specified in the Intent. 在服务中,您实现onHandleIntent来执行Intent中指定的操作。 When the operation is completed you use the passed in ResultReceiver to send a message back to the Activity at which point onReceiveResult will be called. 操作完成后,您可以使用传入的ResultReceiver将消息发送回Activity,这时将调用onReceiveResult。

So for example, you want to pull some data from your Web Service. 因此,例如,您想从Web服务中提取一些数据。

- You create the intent and call startService. -创建意图并调用startService。

- The operation in the service starts and it sends the activity a message saying it started -服务中的操作开始,并向活动发送一条消息,说明活动已开始

- The activity processes the message and shows a progress. -活动处理消息并显示进度。

- The service finishes the operation and sends some data back to your activity. -服务完成操作并将一些数据发送回您的活动。

- Your activity processes the data and puts in in a list view -您的活动处理数据并放入列表视图

- The service sends you a message saying that it is done, and it kills itself. -该服务会向您发送一条消息,说明已完成,并且会杀死自己。

- The activity gets the finish message and hides the progress dialog. -活动获取完成消息并隐藏进度对话框。

Eg: 例如:

The Activity: 活动:

public class HomeActivity extends Activity implements MyResultReceiver.Receiver {

    public MyResultReceiver mReceiver;

    public void onCreate(Bundle savedInstanceState) {
        mReceiver = new MyResultReceiver(new Handler());
        mReceiver.setReceiver(this);
        ...
        final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, QueryService.class);
        intent.putExtra("receiver", mReceiver);
        intent.putExtra("command", "query");
        startService(intent);
    }

    public void onPause() {
        mReceiver.setReceiver(null); // clear receiver so no leaks.
    }

    public void onReceiveResult(int resultCode, Bundle resultData) {
        switch (resultCode) {
        case RUNNING:
            //show progress
            break;
        case FINISHED:
            List results = resultData.getParcelableList("results");
            // do something interesting
            // hide progress
            break;
        case ERROR:
            // handle the error;
            break;
    }
}

The Service: 服务:

public class QueryService extends IntentService {
    protected void onHandleIntent(Intent intent) {
        final ResultReceiver receiver = intent.getParcelableExtra("receiver");
        String command = intent.getStringExtra("command");
        Bundle b = new Bundle();
        if(command.equals("query") {
            receiver.send(STATUS_RUNNING, Bundle.EMPTY);
            try {
                // get some data or something           
                b.putParcelableArrayList("results", results);
                receiver.send(STATUS_FINISHED, b)
            } catch(Exception e) {
                b.putString(Intent.EXTRA_TEXT, e.toString());
                receiver.send(STATUS_ERROR, b);
            }    
        }
        this.stopSelf();
    }
}

ResultReceiver: ResultReceiver:

public MyResultReceiver extends ResultReceiver {
    private Receiver mReceiver;

    public MyResultReceiver(Handler handler) {
        super(handler);
    }

    public void setReceiver(Receiver receiver) {
        mReceiver = receiver;
    }

    public interface Receiver {
        public void onReceiveResult(int resultCode, Bundle resultData);
    }

    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
        if (mReceiver != null) {
            mReceiver.onReceiveResult(resultCode, resultData);
        }
    }
}

Try http://phono.com/ . 尝试http://phono.com/ It provides all kinds of phone APIs. 它提供了各种电话API。

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

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