android-拨打电话单击一个按钮

我在按android中的按钮时正尝试拨打电话

((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

String phno="10digits";

Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));

startActivity(i);

}

});

但是当我运行并单击按钮时,它给了我错误

ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }

我该如何解决这个问题?

13个解决方案

135 votes

您是否已在清单文件中授予权限

在你的活动中

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

startActivity(callIntent);

如果您有任何问题,请告诉我。

Shaista Naaz answered 2020-01-26T04:24:43Z

14 votes

调用/开始调用有两种意图:ACTION_CALL和ACTION_DIAL。

ACTION_DIAL仅会打开填写的dialer with the number,但允许用户实际打开all or reject the call。 ACTION_CALL将立即拨打电话,并且需要额外的许可。

因此,请确保您拥有许可

uses-permission android:name="android.permission.CALL_PHONE"

在您的AndroidManifest.xml中

xmlns:android="http://schemas.android.com/apk/res/android"

package="com.dbm.pkg"

android:versionCode="1"

android:versionName="1.0">

android:icon="@drawable/icon"

android:label="@string/app_name">

Xar E Ahmer answered 2020-01-26T04:25:16Z

12 votes

将您的字符串更改为String phno="tel:10digits";,然后重试。

Harshad answered 2020-01-26T04:25:36Z

10 votes

以上都不起作用,因此需要修改一下对我有用的代码

Intent i = new Intent(Intent.ACTION_DIAL);

String p = "tel:" + getString(R.string.phone_number);

i.setData(Uri.parse(p));

startActivity(i);

kenwen answered 2020-01-26T04:25:56Z

5 votes

我也为此感到难过。 我没有意识到,除了额外的权限外,您还需要在包含数字的字符串后附加“ tel:”。 这是我的功能正常后的样子。 希望这可以帮助。

@Override

public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_DIAL);

String temp = "tel:" + phone;

intent.setData(Uri.parse(temp));

startActivity(intent);

}

JCrooks answered 2020-01-26T04:26:21Z

4 votes

添加“ tel:”以及您要拨打的电话号码,然后开始您的活动。

Intent myIntent = new Intent(Intent.ACTION_CALL);

String phNum = "tel:" + "1234567890";

myIntent.setData(Uri.parse(phNum));

startActivity( myIntent ) ;

Ashu Singh answered 2020-01-26T04:26:41Z

4 votes

要将代码放在一行内,请尝试以下操作:

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456789")));

以及适当的清单许可:

希望这可以帮助!

Brian answered 2020-01-26T04:27:09Z

3 votes

之前检查权限(对于android 6及更高版本):

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==

PackageManager.PERMISSION_GRANTED)

{

context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));

}

javadaskari answered 2020-01-26T04:27:29Z

2 votes

对于使用AppCompat的用户...请尝试此

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Intent;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import android.net.Uri;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button startBtn = (Button) findViewById(R.id.db);

startBtn.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

makeCall();

}

});

}

protected void makeCall() {

EditText num = (EditText)findViewById(R.id.Dail);

String phone = num.getText().toString();

String d = "tel:" + phone ;

Log.i("Make call", "");

Intent phoneIntent = new Intent(Intent.ACTION_CALL);

phoneIntent.setData(Uri.parse(d));

try {

startActivity(phoneIntent);

finish();

Log.i("Finished making a call", "");

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();

}

}

}

然后将此添加到您的清单中,

X-Black... answered 2020-01-26T04:27:53Z

1 votes

设备上支持电话也是很好检查

private boolean isTelephonyEnabled(){

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY

}

Aristo Michael answered 2020-01-26T04:28:13Z

1 votes

I hope, this short code is useful for You,

## Java Code ##

startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+txtPhn.getText().toString())));

----------------------------------------------------------------------

Please check Manifest File,(for Uses permission)

## Manifest.xml ##

xmlns:android="http://schemas.android.com/apk/res/android"

package="com.dbm.pkg"

android:versionCode="1"

android:versionName="1.0">

## uses-permission for Making Call ##

android:icon="@drawable/icon"

android:label="@string/app_name">

RajeshkumarG answered 2020-01-26T04:28:28Z

0 votes

我刚刚在Android 4.0.2设备(GN)上解决了该问题,并且适用于该设备/版本的唯一版本类似于具有CALL_PHONE权限并回答的第一个5星标:

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

startActivity(callIntent);

使用任何其他解决方案,我在此设备/版本上都收到了ActivityNotFoundException。较旧的版本呢? 有人会提供反馈吗?

BossOss answered 2020-01-26T04:28:53Z

0 votes

经许可:

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:9875432100"));

if (ActivityCompat.checkSelfPermission(yourActivity.this,android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(yourActivity.this,

android.Manifest.permission.CALL_PHONE)) {

} else {

ActivityCompat.requestPermissions(yourActivity.this,

new String[]{android.Manifest.permission.CALL_PHONE},

MY_PERMISSIONS_REQUEST_CALL_PHONE);

}

}

startActivity(callIntent);

Santhosh answered 2020-01-26T04:29:13Z

android点击号码打电话,android-拨打电话单击一个按钮相关推荐

  1. android点击号码打电话,Android从虚拟号码拨打电话

    你可以检查 this link,它使用电话api.请查看15.1.3示例:确定呼叫状态. 我也在这里粘贴示例代码: private class ListenToPhoneState extends P ...

  2. android跳转到打电话,Android 应用跳转到拨打电话界面或qq进行聊天(qq咨询)

    拨打电话: /** * 调用拨号界面 * @param phone 电话号码 */ public void callPhone(String phone) { Intent intent = new ...

  3. Android 动态权限申请 BaseActivity 封装 拨打电话

    志在巅峰的攀登者,不会陶醉在沿途的某个脚印之中,在码农的世界里,优美的应用体验,来源于程序员对细节的处理以及自我要求的境界,年轻人也是忙忙碌碌的码农中一员,每天.每周,都会留下一些脚印,就是这些创作的 ...

  4. Android 12.0 禁用和启用拨打电话功能实现

    1.项目需求 在12.0的产品定制化开发中,在一些wifi产品的产品开发中,对于系统4g部分的功能需要裁剪 比如拨打电话 接听电话 短信功能等这部分 需要禁用系统对应的功能,接下来就来初步分析下系统中 ...

  5. android 点击图片事件,android图文混排点击事件

    图文混排顾名思义就是把文字和图片混合排列在一起,比较简单的需求我们也可以通过TextView和ImageView配合使用来达到目的,但是遇到稍微复杂一些的情况这种方法就不适用了. 做这样一个按钮: 对 ...

  6. android 点击图标重启,Android应用第一次安装成功点击“打开”后Home键切出应用后再点击桌面图标返回导致应用重启问题的解决方法...

    Android应用第一次安装成功点击"打开"后Home键切出应用后再点击桌面图标返回导致应用重启问题的解决方法 if((getIntent().getFlags() & I ...

  7. android点击选择相册,android: 从相册中选择照片

    虽然调用摄像头拍照既方便又快捷,但并不是每一次我们都需要去当场拍一张照片的. 因为每个人的手机相册里应该都会存有许许多多张照片,直接从相册里选取一张现有的照 片会比打开相机拍一张照片更加常用.一个优秀 ...

  8. Android点击无响应,Android Studio无响应打不开的解决办法

    最近谷歌发布了Android Studio,下载安装之后,在使用时发现一个问题,那就是发布无响应且无法启动,也就是点击Android图标的时候没有任务反应,我想说的是你需要重新配置一下环境~ 因为这个 ...

  9. android按钮旋转,单击一个按钮在android中顺时针旋转图像

    我有一个要求,我有一个ImageView和一个按钮. 我想在单击按钮时旋转图像.我需要全屏图像.但是当我点击按钮图像时会旋转,但不会在全屏显示.请参阅以下链接. 之后,当我点击按钮图像时也会旋转.但是 ...

最新文章

  1. PHP开发之thinkPHP分层设计
  2. 如何评估AI在医学影像识别中的应用效果?
  3. 6/7 SELECT语句:过滤(正则表达式REGEXP)
  4. oracle tabs作用,Oracle 中 table 函数的应用浅析
  5. [深度学习] 分布式模式介绍(一)
  6. EasyUI界面显示中文格式(日期中文格式)
  7. uitextfield 键盘类型_以编程方式更改UITextField键盘类型
  8. amd860k能装黑苹果吗_可以黑苹果,性能比同价位的GTX1650强,RX580 2048SP不香吗?...
  9. mysql 360怎么安装_mysql 5.7 安装配置方法图文教程
  10. 汉字应用能力计算机上打印文字,宣传|《汉字应用水平等级及测试大纲》,你能考几级?...
  11. 用户与计算机的交互界面是什么,终于知道交互界面设计是什么
  12. MVX-Net | 多模型三位像素网络用于3D目标检测
  13. “3G域名”遭恶炒 用友移动代理被指画饼圈钱
  14. linux自带截图工具使用
  15. 电力,地铁,医生等行业值班员全能倒班日历助手
  16. uniapp微信小程序瀑布流布局
  17. 用Python爬取王者农药英雄皮肤 原
  18. Redis持久化RDB/AOF详解与实践
  19. redis密码、端口号、连接IP的修改
  20. 论文翻译:2000_narrowband to wideband conversion of speech using GMM based transformation

热门文章

  1. 掌握“盘带技术”——比较磁盘存储和磁带存储
  2. WIN7 安装 SQL2000
  3. 微信服务号和订阅号的五大区别,如何选择申请微信公众号
  4. 张爱玲经典爱情语录大全
  5. 计算机无法识别出硬件,电脑检测不到网卡硬件信息怎么办
  6. 罗永浩跟罗振宇八个半小时都聊了些什么
  7. 老板电器携手华为HarmonyOS创新升级中国厨房新理念
  8. jacob不能在Linux系统使用!
  9. android JavaMail报错:SendFailedException: No recipient addresses
  10. Email营销课堂:邮件群发平台与软件区别