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

相关文章

使用TomCat,service输出台出现乱码的解决

《使用TomCat,service输出台出现乱码的解决》本文介绍了解决Tomcat服务输出台中文乱码问题的两种方法,第一种方法是修改`logging.properties`文件中的`prefix`和`... 目录使用TomCat,service输出台出现乱码问题1解决方案问题2解决方案总结使用TomCat,

解决Spring运行时报错:Consider defining a bean of type ‘xxx.xxx.xxx.Xxx‘ in your configuration

《解决Spring运行时报错:Considerdefiningabeanoftype‘xxx.xxx.xxx.Xxx‘inyourconfiguration》该文章主要讲述了在使用S... 目录问题分析解决方案总结问题Description:Parameter 0 of constructor in x

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

Java循环创建对象内存溢出的解决方法

《Java循环创建对象内存溢出的解决方法》在Java中,如果在循环中不当地创建大量对象而不及时释放内存,很容易导致内存溢出(OutOfMemoryError),所以本文给大家介绍了Java循环创建对象... 目录问题1. 解决方案2. 示例代码2.1 原始版本(可能导致内存溢出)2.2 修改后的版本问题在

大数据小内存排序问题如何巧妙解决

《大数据小内存排序问题如何巧妙解决》文章介绍了大数据小内存排序的三种方法:数据库排序、分治法和位图法,数据库排序简单但速度慢,对设备要求高;分治法高效但实现复杂;位图法可读性差,但存储空间受限... 目录三种方法:方法概要数据库排序(http://www.chinasem.cn对数据库设备要求较高)分治法(常

Vue项目中Element UI组件未注册的问题原因及解决方法

《Vue项目中ElementUI组件未注册的问题原因及解决方法》在Vue项目中使用ElementUI组件库时,开发者可能会遇到一些常见问题,例如组件未正确注册导致的警告或错误,本文将详细探讨这些问题... 目录引言一、问题背景1.1 错误信息分析1.2 问题原因二、解决方法2.1 全局引入 Element

linux报错INFO:task xxxxxx:634 blocked for more than 120 seconds.三种解决方式

《linux报错INFO:taskxxxxxx:634blockedformorethan120seconds.三种解决方式》文章描述了一个Linux最小系统运行时出现的“hung_ta... 目录1.问题描述2.解决办法2.1 缩小文件系统缓存大小2.2 修改系统IO调度策略2.3 取消120秒时间限制3

关于@MapperScan和@ComponentScan的使用问题

《关于@MapperScan和@ComponentScan的使用问题》文章介绍了在使用`@MapperScan`和`@ComponentScan`时可能会遇到的包扫描冲突问题,并提供了解决方法,同时,... 目录@MapperScan和@ComponentScan的使用问题报错如下原因解决办法课外拓展总结@

MybatisGenerator文件生成不出对应文件的问题

《MybatisGenerator文件生成不出对应文件的问题》本文介绍了使用MybatisGenerator生成文件时遇到的问题及解决方法,主要步骤包括检查目标表是否存在、是否能连接到数据库、配置生成... 目录MyBATisGenerator 文件生成不出对应文件先在项目结构里引入“targetProje

C#使用HttpClient进行Post请求出现超时问题的解决及优化

《C#使用HttpClient进行Post请求出现超时问题的解决及优化》最近我的控制台程序发现有时候总是出现请求超时等问题,通常好几分钟最多只有3-4个请求,在使用apipost发现并发10个5分钟也... 目录优化结论单例HttpClient连接池耗尽和并发并发异步最终优化后优化结论我直接上优化结论吧,