Android中Intent的用法介绍
2015-07-18 23:23
671 查看
1.调用系统自带浏览器
2.调用google搜索相应的内容
3.发短信(进入系统编辑短信界面)
添加权限:
4.打电话
5.卸载apk
6.安装apk
这里提供一个可行的函数,
http://blog.csdn.net/johnsonblog/article/details/7581070
http://edison-cool911.iteye.com/blog/695077
7.Intent实现页面跳转与传递参数
传递参数并跳转
接收参数
我写了以上代码的测试demo,需要的可以下载看看
源码
链接:http://pan.baidu.com/s/1i3ImBvJ 密码:h0ab
Uri uri = Uri.parse("http://www.baidu.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity"); startActivity(intent);添加权限:
</pre><pre name="code" class="java"><uses-permission android:name="android.permission.INTERNET"></uses-permission>
2.调用google搜索相应的内容
Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, "search keywords"); startActivity(intent);
3.发短信(进入系统编辑短信界面)
Uri uri = Uri.parse("smsto:" + "13312966705"); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra("sms_body", "sms content"); startActivity(intent);
添加权限:
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
4.打电话
Uri uri = Uri.parse("tel:" + "13312966705"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent);添加权限:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
5.卸载apk
Uri uri = Uri.fromParts("package", strPackageName, null); Intent intent = new Intent(Intent.ACTION_DELETE, uri); startActivity(intent);
6.安装apk
这里提供一个可行的函数,
private void installApp(Context context, File appFile) { // 创建URI Uri uri = Uri.fromFile(appFile); // 创建Intent意图 Intent intent = new Intent(Intent.ACTION_VIEW); // 设置Uri和类型 intent.setDataAndType(uri, "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 执行意图进行安装 context.startActivity(intent); }另外关于intent安装apk的例子文章大家可以参考这两篇文章
http://blog.csdn.net/johnsonblog/article/details/7581070
http://edison-cool911.iteye.com/blog/695077
7.Intent实现页面跳转与传递参数
传递参数并跳转
<span style="white-space:pre"> </span>Intent intent = new Intent(); //Intent传递参数 intent.putExtra("testIntent", "123"); intent.setClass(FirstActivity.this, SecondActivity.class); FirstActivity.this.startActivity(intent);
接收参数
<span style="font-weight: bold; white-space: pre;"> </span>//使用Intent对象得到FirstActivity传递来的参数 Intent intent = getIntent(); String value = intent.getStringExtra("testIntent");
我写了以上代码的测试demo,需要的可以下载看看
源码
链接:http://pan.baidu.com/s/1i3ImBvJ 密码:h0ab
相关文章推荐
- Android源码编译——Ubuntu 14.10的make3.8、gcc-4.4.7和g++-4.4.7安装方法
- android左右侧滑菜单控件的简易实现
- 我的Android进阶之旅------>四种呼叫转移场景
- Android开发环境搭建
- android 文件存储 Internal storage External storage
- 启动安卓模拟器时出现 The connection to adb is down, and a severe error has occured
- Android TV 视图体系分析
- Android基础入门教程——1.2 开发环境搭建
- Android开发中的menu菜单
- Android手机开机自动启动
- Android enum(枚举类型)使用详解
- 转:Android 设置屏幕不待机
- Android Studio 1.3 以及NDK功能尝鲜
- Android屏幕适配全攻略(最权威的官方适配指导)
- running android lint has encountered a
- Android开发相关的Blog推荐——跟随大神的脚步才能成长为大神
- android com.handmark.pulltorefresh 使用技巧
- android开发之调试技巧
- android开发之调试技巧
- android开发之调试技巧