Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
2012-02-24 15:36
781 查看
资料视频可参考传智播客 打电话视频
一:布局文件先设计拨号器的简单界面,可以先用画图软件构思 界面
二 :Activity中进行获取EditText中的电话号码,然后点击,使用Intent(意图)进行实现打电话的功能
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile));
三:注意必须在AndroidManifset,xml文件进行打电话的权限设置
核心源代码 (包自己去引)
strings.xml
main.xml
这里其实最重要的就要属权限设置,打电话权限, 还有理解 intent 意图 (行为,行为数据)的用法
一:布局文件先设计拨号器的简单界面,可以先用画图软件构思 界面
二 :Activity中进行获取EditText中的电话号码,然后点击,使用Intent(意图)进行实现打电话的功能
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile));
三:注意必须在AndroidManifset,xml文件进行打电话的权限设置
核心源代码 (包自己去引)
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" /> 如图所示这三个控件是垂直摆放的,所以要使用线性布局来搁置显示控件效果图: </LinearLayout>
这里其实最重要的就要属权限设置,打电话权限, 还有理解 intent 意图 (行为,行为数据)的用法
相关文章推荐
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android使用系统Intent实现分享功能及将应用加入分享列表
- Android使用系统Intent实现分享功能及将应用加入分享列表
- Android使用系统Intent实现分享功能及将应用加入分享列表++分享邮箱实现
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- 【Android】菜单功能的实现:使用XML
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android----Intent,运用由android系统帮助匹配实现打电话、发送短信、打开网页、播放音乐、打开视频、打开图片、安装APK、通知栏消息、拍照上传头像等功能
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- 实现照相功能需要添加的权限和硬件在androidmanifest.xml文件中
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- Android 图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!