Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
来源:互联网 发布:网络舆情监测员 编辑:程序博客网 时间:2024/06/11 03:33
- 一:布局文件先设计拨号器的简单界面,可以先用画图软件构思 界面
- 二 :Activity中进行获取EditText中的电话号码,然后点击,使用Intent(意图)进行实现打电话的功能
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(“tel:”+ mobile)); 三:注意必须在AndroidManifset,xml文件进行打电话的权限设置
<uses-permission android:name="android.permission.CALL_PHONE" />
核心源代码
public class PhoneDuanXINActivity extends Activity { private EditText mobileText; //在这里写个成员变量,就可以直接调用 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mobileText = (EditText)this.findViewById(R.id.mobile); //调用成员变量mobileText 强转给右边 // 使用匿名类进行加监听 Button button = (Button)this.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ String mobile = mobileText.getText().toString(); //得到了用户输入的手机号 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile )); //意图 Intent(行为, 行为数据) intent类用于描述一个应用将会做什么事 在windos中就有种东西 开始菜单》》运行》》 http://www.baidu.com 它可以直接打开,这是为什么? 是因为浏览器 认出了http: startActivity(intent); //这就是内部类访问外部类的实例 } }); } }
strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">下午好</string> <string name="app_name">摩托罗拉手机 拨号器</string> <string name="mobile">请输入号码</string> <string name="button">拨打</string> </resources>
main.xml
<?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/mobile" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id = "@+id/mobile" /> <Button android:layout_width ="wrap_content" android:layout_height="wrap_content" android:text = "@string/button" android:id = "@+id/button" /> <p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; text-align: left; "><span style="font-family: 'Microsoft YaHei'; color: rgb(102, 102, 102); "><span style="font-size:13px;">如图所示这三个控件是垂直摆放的,所以要使用线性布局来搁置显示控件</span></span></p><p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; text-align: left; "><strong><span style="font-family: 'Microsoft YaHei'; color: rgb(102, 102, 102); "><span style="font-size:13px;">效果图:</span></span></strong></p> </LinearLayout>
这里其实最重要的就要属权限设置,打电话权限, 还有理解 intent 意图 (行为,行为数据)的用法
0 0
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android中Intent的Action和权限
- Android实现打电话功能
- Android实现打电话功能
- Android模拟打电话功能的实现
- Android使用系统Intent实现分享功能及将应用加入分享列表
- 打电话功能的实现
- 打电话功能的实现
- Android 实现打电话功能demo
- android Intent 启动拨号 实现打电话
- 实现打电话和发短息功能
- 实现照相功能需要添加的权限和硬件在androidmanifest.xml文件中
- Android学习笔记(5)- Intent与权限,打电话的例子
- android实现打电话和发短信的功能(10学员张晓丛)
- 【Android】菜单功能的实现:使用XML
- 高级控件之星际评分条(RatingBar)的使用
- 利用StringEscapeUtils对字符串进行各种转义与反转义(Java)
- Android底部导航栏实现(三)之TextView+LinearLayout
- json知识(1)
- LV10算法实现与分析
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 面向未来的跨界开发技术(上)
- SQLite 语句
- ScrollView中嵌套Listview
- ubuntu python3.5安装搭建
- 移动端文件直传到阿里云oss流程包括代码
- 求生之路服务器参数配置
- 当参数缺失或异常时重新显示输入表单
- ireport