130

我正在将要通过捆绑调用的号码传递给活动

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

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

出了点问题,因为当我按下按钮时没有任何反应......

我究竟做错了什么?

PD:我正在使用Android 1.5 兼容项目...可能电话与1.5 不兼容?

4

10 回答 10

267

你忘了调用 startActivity。它应该如下所示:

Intent intent = new Intent(Intent.ACTION_CALL);

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

意图本身就是描述某事的对象。它什么也没做。

不要忘记在清单中添加相关权限:

<uses-permission android:name="android.permission.CALL_PHONE" />
于 2011-01-27T13:16:39.260 回答
24

在我的手机上试过这个,效果很好。

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

在清单文件中添加此权限。

<uses-permission android:name="android.permission.CALL_PHONE" />
于 2012-08-24T04:58:47.040 回答
13
 Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+198+","+1+","+1)); 
             startActivity(callIntent);

用于多个有序调用

这用于 DTMF 呼叫系统。如果电话掉线,你应该在数字之间传递更多的“,”。

于 2011-08-26T11:53:18.747 回答
3

看看那里:http: //developer.android.com/guide/topics/intents/intents-filters.html

您是否已更新清单文件以授予呼叫权限?

于 2011-01-27T13:16:48.833 回答
3

这不需要许可。

val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:+123456"))
startActivity(intent)

或者

val intent = Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "+123456", null))
startActivity(intent)

但它又显示了一个对话框(询问您是想打一次电话还是总是打一次电话)。所以最好使用ACTION_CALL权限(请参阅撤销权限 android.permission.CALL_PHONE)。

于 2019-09-26T15:17:10.793 回答
2

在这里,我将向您展示如何从您的活动中拨打电话。要拨打电话,您必须在您的应用程序中输入此代码。

try {
    Intent my_callIntent = new Intent(Intent.ACTION_CALL);
    my_callIntent.setData(Uri.parse("tel:"+phn_no));
    //here the word 'tel' is important for making a call...
    startActivity(my_callIntent);
} catch (ActivityNotFoundException e) {
    Toast.makeText(getApplicationContext(), "Error in your phone call"+e.getMessage(), Toast.LENGTH_LONG).show();
}
于 2012-10-20T23:01:34.967 回答
2

它工作得很好。这样,您不需要获得用户的许可。您可以直接打开电话呼叫部分。

诀窍,使用ACTION_DIAL而不是ACTION_CALL

private void callPhoneNumber() {
    String phone = "03131693169";
    Intent callIntent = new Intent(Intent.ACTION_DIAL);
    callIntent.setData(Uri.parse("tel:" + phone));
    startActivity(callIntent);
}
于 2020-09-05T19:26:46.230 回答
0
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
   final Button button = (Button) findViewById(R.id.btn_call);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String mobileNo = "123456789";
            String uri = "tel:" + mobileNo.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });*
 }
于 2014-03-20T06:47:49.080 回答
0

如果您最终遇到 SecurityException(并且呼叫不起作用),您应该考虑请求用户权限以进行呼叫,因为这被认为是危险的权限:

ActivityCompat.requestPermissions(
    activity,
    new String[] {Manifest.permission.CALL_PHONE},
    1
);

请注意,这与清单权限无关(您也必须拥有)

于 2020-10-03T15:20:17.507 回答
0

如果有人在 Kotlin中寻找

    val  uri = "tel:+800******"
    val call_customer_service = Intent(Intent.ACTION_CALL)
    call_customer_service.setData(Uri.parse(uri))
    startActivity(call_customer_service)

像其他一些解决方案一样,它需要android.permission.CALL_PHONE许可。

于 2019-04-15T05:38:59.720 回答