android - Android 呼叫电话号码侧边菜单
问题描述
我正忙于制作我的第一个 android 应用程序,我正在寻找创建以下选项:当有人从“activit_main_drawer.xml”点击“联系我们”时,他们将直接拨打“电话号码”
有谁能帮助我吗?:)
这就是“按钮”的调用方式
<item
android:id="@+id/nav_belnu"
android:icon="@drawable/ic_phone_square_solid"
android:title="BEL nu" />
解决方案
在你的按钮的 onclick 监听器中,你可以这样进行,记得在你的项目的清单文件中添加调用权限:
private void makeCall(String phoneNumber){
try {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(intent);
}catch (Exception e)
{
e.printStackTrace();
}
}
推荐阅读
- ssh - 如何通过 ssh 传递带引号的参数
- mysql - Mysql - 我可以有一个在删除父母时不会被删除的孩子吗?
- tensorflow - Tensorflow 管道,批量预处理:初学者问题
- vb.net - 通过 COM 从 VB6 访问嵌套的 VB.NET 类
- ios - IOS中的领域:插入对象后无法更改主键
- java - Hibernate:在广泛的类层次结构中有效地加载具有祖先类型的对象列表
- reason - 在 ReasonReact 中处理孩子
- spring - SpringBoot - 解析 HTTP 请求标头时出错(Oauth2 https 端点)
- laravel - 从查询中的日期属性获取年份
- ionic-framework - 无法在 IONIC 中的另一个类 app.component.ts 上获取存储变量