如何打个电话编程? [英] How to make a phone call programatically?

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

问题描述

即时传递给一个活动的数量由包叫

im passing to a activity the number to call by a bundle

然后,在这样的活动中,我有一个按钮来调用这个数字,这是code:

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")));
            }
        }); 

什么是错的,因为当我preSS按钮没有反应......

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天全站免登陆