Android APP拨打电话android.permission授权后报错问题解决

2024-01-14 12:30

本文主要是介绍Android APP拨打电话android.permission授权后报错问题解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

思路:APP通过Intent来实现拨号功能。

一、首先在manifest下的AndroidManifest.xml文件中进行授权:

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

演示时发现仅此操作仍不能运行,界面不能显示,报错提示如下:

错误提示:java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{5f1635b 10632:com.example.myapp2/u0a88} (pid=10632, uid=10088) with revoked permission android.permission.CALL_PHONE

这是因为需要在虚拟机中的setting中进行设置,真机演示的方法也类似。方法如下:

1)选择设置

2)找到Apps

3) 选择App info

4) 找到我的APP

5) 选择Permissions

6)打开拨号权限 

 

 

二、演示方式一运行如下,点击拨打电话即把默认的号进行拨号:

三、关键代码之MainActivity

  在文件中先声明Intent对象,再使用startActivity方法启动,具体如下:

package com.example.myapp2;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Bundle;
import android.widget.EditText;
//AppCompatActivity
public class MainActivity extends Activity {private Button button;private EditText editText;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button = (Button)findViewById(R.id.button);button.setOnClickListener(new buttonListener());//放在此可实现运行APP即拨号//Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+number));//startActivity(intent);}class buttonListener implements OnClickListener{@Overridepublic void onClick(View v){editText = (EditText) findViewById(R.id.edittext);String number = editText.getText().toString();//方式一 是直接进行呼叫的方式Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+number));//方式二 不直接进行呼叫,而是启动 Android 系统的拨号应用程序,由用户进行拨号。不//要任何权限的设置//Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+number));startActivity(intent);}}}

四、关键代码之activity_main.xml

 文件内容如下,当然也可把号码放进strings.xml文件里,然后通过android:text="@string/tel_x"的方式填写号码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><EditTextandroid:id="@+id/edittext"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="555666"android:layout_marginLeft="40dp"android:layout_marginTop="30dp"/><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="80dp"android:layout_marginTop="40dp"android:text="拨打电话" /></LinearLayout>

这篇关于Android APP拨打电话android.permission授权后报错问题解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/605156

相关文章

线上Java OOM问题定位与解决方案超详细解析

《线上JavaOOM问题定位与解决方案超详细解析》OOM是JVM抛出的错误,表示内存分配失败,:本文主要介绍线上JavaOOM问题定位与解决方案的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录一、OOM问题核心认知1.1 OOM定义与技术定位1.2 OOM常见类型及技术特征二、OOM问题定位工具

C++右移运算符的一个小坑及解决

《C++右移运算符的一个小坑及解决》文章指出右移运算符处理负数时左侧补1导致死循环,与除法行为不同,强调需注意补码机制以正确统计二进制1的个数... 目录我遇到了这么一个www.chinasem.cn函数由此可以看到也很好理解总结我遇到了这么一个函数template<typename T>unsigned

Vue3绑定props默认值问题

《Vue3绑定props默认值问题》使用Vue3的defineProps配合TypeScript的interface定义props类型,并通过withDefaults设置默认值,使组件能安全访问传入的... 目录前言步骤步骤1:使用 defineProps 定义 Props步骤2:设置默认值总结前言使用T

504 Gateway Timeout网关超时的根源及完美解决方法

《504GatewayTimeout网关超时的根源及完美解决方法》在日常开发和运维过程中,504GatewayTimeout错误是常见的网络问题之一,尤其是在使用反向代理(如Nginx)或... 目录引言为什么会出现 504 错误?1. 探索 504 Gateway Timeout 错误的根源 1.1 后端

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

解决升级JDK报错:module java.base does not“opens java.lang.reflect“to unnamed module问题

《解决升级JDK报错:modulejava.basedoesnot“opensjava.lang.reflect“tounnamedmodule问题》SpringBoot启动错误源于Jav... 目录问题描述原因分析解决方案总结问题描述启动sprintboot时报以下错误原因分析编程异js常是由Ja

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

深度剖析SpringBoot日志性能提升的原因与解决

《深度剖析SpringBoot日志性能提升的原因与解决》日志记录本该是辅助工具,却为何成了性能瓶颈,SpringBoot如何用代码彻底破解日志导致的高延迟问题,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言第一章:日志性能陷阱的底层原理1.1 日志级别的“双刃剑”效应1.2 同步日志的“吞吐量杀手”

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec