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

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

2015-01-28 16:42 429 查看
使用意图调用内置应用程序



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。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐