如何以编程方式拨打电话? [英] How to make a phone call programmatically?

查看:161
本文介绍了如何以编程方式拨打电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将要捆绑发送的电话号码传递给活动

I'm passing to an activity the number to call by a bundle

然后,在这样的活动中,我有一个按钮可以拨打该号码,这是代码:

and then, in such activity, I have a button to call to that number, this is the code:

callButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(bundle.getString("mobilePhone")));
            }
        }); 

出了点问题,因为当我按下按钮时什么也没发生...

Something is wrong, because when I press the button nothing happens...

我在做什么错了?

PD:我正在使用与Android 1.5兼容的项目...也许电话与1.5不兼容?

PD: I'm using Android 1.5 compatible project... maybe phone call is incompatible to 1.5?

推荐答案

您忘记了调用startActivity.它应该看起来像这样:

You forgot to call startActivity. It should look like this:

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);

意图本身仅仅是描述某些内容的对象.它什么也没做.

An intent by itself is simply an object that describes something. It doesn't do anything.

请不要忘记将相关权限添加到您的清单中

Don't forget to add the relevant permission to your manifest:

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

这篇关于如何以编程方式拨打电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆