【问题标题】:Call Number from Android App from Native calling app programatically以编程方式从本机调用应用程序调用来自 Android 应用程序的电话号码
【发布时间】:2015-11-27 21:16:56
【问题描述】:

我使用以下权限从我的应用程序拨打电话

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

这是我拨打电话的代码。

 Intent iniCall=new Intent(Intent.ACTION_CALL);
 iniCall.setData(Uri.parse("tel:9849199291");
 startActivity(iniCall);   

但它会启动 Skype 应用程序,而不是启动默认呼叫应用程序。

如何从默认调用应用程序调用?

【问题讨论】:

标签: android


【解决方案1】:

对于Pre-Lollipop 设备,您需要使用com.android.phone 作为包名,在Lollipop 中,您需要使用com.android.server.telecom 作为包名。

试试这个代码:

Intent iniCall=new Intent(Intent.ACTION_CALL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
   iniCall.setPackage("com.android.server.telecom"); 
}else{
   iniCall.setPackage("com.android.phone"); 
} 
iniCall.setData(Uri.parse("tel:"+9849199291);
startActivity(iniCall); 

希望对你有帮助!

【讨论】:

    【解决方案2】:

    主要活动代码:

      button.setOnClickListener(new OnClickListener() {
    
        @Override
       public void onClick(View arg0) {
        String phnum = edittext.getText().toString();
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + phnum));
        startActivity(callIntent);
       }
      });
    

    清单:

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

    【讨论】:

      【解决方案3】:

      我个人更喜欢不需要权限,但需要用户在拨号盘中按拨号的方法,如下所示:

      Uri uri = Uri.parse("tel:" + number);
      Intent callIntent = new Intent(Intent.ACTION_DIAL, uri);
      context.startActivity(callIntent); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-03
        • 2012-09-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多