本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
我们已经了解了如何在自己的单个应用中调用activity。但是,android开发中比较重要的一点,就是使用intent调用其他应用的activity。特别地,你的应用可以调用系统中的许多“内置”应用。所谓的“内置”应用,指的就是系同级别的应用,比如Browser,Phone,Sms等等。举个例子,如果你的应用需要打开一个网页,可以使用Intent对象去调用浏览器,浏览器把网页显示出来,而不是要自己创建一个浏览器。。。
下面的例子展示如何调用系统中的几个比较常用的“内置”应用。
1. 创建一个工程,Intents。
2. main.xml中的代码。
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
- <Button
- android:id="@+id/btn_webbrowser"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:onClick="onClickWebBrowser"
- android:text="WebBrowser"/>
- <Button
- android:id="@+id/btn_makecalls"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:onClick="onClickMakeCalls"
- android:text="MakeCalls"/>
- <Button
- android:id="@+id/btn_showMap"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:onClick="onClickShowMap"
- android:text="ShowMap"/>
- <Button
- android:id="@+id/btn_launchMyBrowser"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:onClick="onClickLaunchMyBrowser"
- android:text="LaunchMyBrowser"/>
- </LinearLayout>
3. IntentsActivity.java中的代码。
- publicclassIntentsActivityextendsActivity{
- intrequest_Code=1;
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- publicvoidonClickWebBrowser(Viewview){
- Intenti=newIntent("android.intent.action.VIEW");
- i.setData(Uri.parse("http://www.amazon.com"));
- startActivity(i);
- }
- publicvoidonClickMakeCalls(Viewview){
- Intenti=newIntent(android.content.Intent.ACTION_DIAL,
- Uri.parse("tel:+651234567"));
- startActivity(i);
- }
- publicvoidonClickShowMap(Viewview){
- Intenti=newIntent(android.content.Intent.ACTION_VIEW,
- Uri.parse("geo:37.827500,-122.481670"));
- startActivity(i);
- }
- }
4. 调试。
程序启动之后:
点击WebBrowser按钮:
点击MakeCalls按钮:
分享到:
相关推荐
Android中使用Intent获取其他应用程序信息的方法介绍.pdf 学习资料 复习资料 教学资源
文档介绍了简介,一、抽象描述要描述什么,二、 Android如何解析Intent,三、应用例子,Activity之com.google.android.notepad.NotesList
android 利用intent调用activity 简明精炼的例子 传递数据,并且有返回值
Android应用源码之Intent_Intent
Android入门程序_Intent的使用
本文实例讲述了Android开发中使用Intent打开第三方应用及验证可用性的方法。分享给大家供大家参考,具体如下: Android中提供了Intent机制来协助应用间的交互与通讯。可作为不同组件之间通讯的媒介完成应用之间的...
Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面.
的 Android SDK 提供了在 Android 平台上使用 JaVa 语言进行 Android 应用开发必须的工具和 API 接口。 特性 • 应用程序框架 支持组件的重用与替换 • Dalvik Dalvik Dalvik Dalvik 虚拟机 专为移动设备优化 • ...
Android APP掉用系统的应用程序,调用安卓手机系统短信,拨打电话,打开相册,拍照,发邮件等
Android应用源码之Intent1_Intent
Android应用核心Intent
在Android应用中通过Intent跳转地图应用(百度地图、高德地图),进行路线规划,如果没有安装则打开网页百度地图进行路线规划。
Android中关于Broadcast、Intent 的应用,对于初学Android者有较大帮助。
Android 官方SDK文档 Intent。Android 官方SDK文档 Intent
android-犯罪意图 android-criminal-intent 的教程应用程序
《Android开发案例驱动教程》 配套代码。 注: 由于第12,13,14章代码太大,无法上传到一个包中。 这三节代码会放到其他压缩包中。 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式...
本文实例讲述了Android使用Intent启动其他非系统应用程序的方法。分享给大家供大家参考,具体如下: android应用程序内部通过Intent来实现Activity间的跳转。也知道通过Intent调用系统程序。但若想在应用程序A内开启...
Android使用Intent实现Video功能
android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码
android中使用隐式intent完成应用的步骤及核心代码2022优秀文档.pptx