您的位置:首页 > 移动开发 > Android开发

Android学习笔记(十七)——使用意图调用内置应用程序

2014-05-20 10:53 555 查看
使用意图调用内置应用程序

1、创建一个新的Android项目并命名为Intents,在main.xml文件中添加两个Button:
<Button
android:id="@+id/btn_webbrowser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onClickWebBrowser"
android:text="Web Browser" />

<Button
android:id="@+id/btn_makecalls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onClickMakeCalls"
android:text="Make Calls" />



2、在IntentsActivity.java文件中添加如下代码:
public void onClickWebBrowser(View v) {//浏览器
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://网址"));//网址处输入百度网址,CSDN不让直接写网址...
startActivity(intent);
}

public void onClickMakeCalls(View v) {//打电话
Intent intent = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+651234567"));
startActivity(intent);
}



3、运行程序,效果如下:



点击Web Browser:



点击Make Calls:



总结:
在Android中,意图通常是成对出项:动作(Action)和数据(data)。动作描述了要执行什么,数据则指定了受影响的对象。
动作的一些示例:Action_VIEW、ACTION_DIAL、ACTION_PICK;
数据的一些示例:tel:+651234567、geo:37.827500,-122.481670、content://contacts。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐