- 浏览: 174089 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
柨灬柨:
:oops: [color=red][list]
[*]
不 ...
Socket通信总结 -
juren007:
你好,我最近遇到一个问题就是NIO下面缓冲区的分包,不知如何解 ...
解决TCP网络传输“粘包”问题 -
s170285:
<script>alert('1');</s ...
使用ViewHolder模式
Intent用法实例
1.无参数Activity跳转
Intent it = new Intent(Activity.Main.this, Activity2.class);
startActivity(it);
2.向下一个Activity传递数据(使用Bundle和Intent.putExtras)
Intent it = new Intent(Activity.Main.this, Activity2.class);
Bundle bundle=new Bundle();
bundle.putString("name", "This is from MainActivity!");
it.putExtras(bundle); // it.putExtra(“test”, "shuju”);
startActivity(it); // startActivityForResult(it,REQUEST_CODE);
对于数据的获取可以采用:
Bundle bundle=getIntent().getExtras();
String name=bundle.getString("name");
3.向上一个Activity返回结果(使用setResult,针对startActivityForResult(it,REQUEST_CODE)启动的Activity)
Intent intent=getIntent();
Bundle bundle2=new Bundle();
bundle2.putString("name", "This is from ShowMsg!");
intent.putExtras(bundle2);
setResult(RESULT_OK, intent);
4.回调上一个Activity的结果处理函数(onActivityResult)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE){
if(resultCode==RESULT_CANCELED)
setTitle("cancle");
else if (resultCode==RESULT_OK) {
String temp=null;
Bundle bundle=data.getExtras();
if(bundle!=null) temp=bundle.getString("name");
setTitle(temp);
}
}
}
下面是转载来的其他的一些Intent用法实例(转自javaeye)
显示网页
1. Uri uri = Uri.parse("http://google.com");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
显示地图
1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //其他 geo URI 範例
5. //geo:latitude,longitude
6. //geo:latitude,longitude?z=zoom
7. //geo:0,0?q=my+street+address
8. //geo:0,0?q=business+near+city
9. //google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
路径规划
1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456
打电话
1. //叫出拨号程序
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_DIAL, uri);
4. startActivity(it);
1. //直接打电话出去
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_CALL, uri);
4. startActivity(it);
5. //用這個,要在 AndroidManifest.xml 中,加上
6. //<uses-permission id="android.permission.CALL_PHONE" />
传送SMS/MMS
1. //调用短信程序
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. it.putExtra("sms_body", "The SMS text");
4. it.setType("vnd.android-dir/mms-sms");
5. startActivity(it);
1. //传送消息
2. Uri uri = Uri.parse("smsto://0800000123");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. it.putExtra("sms_body", "The SMS text");
5. startActivity(it);
1. //传送 MMS
2. Uri uri = Uri.parse("content://media/external/images/media/23");
3. Intent it = new Intent(Intent.ACTION_SEND);
4. it.putExtra("sms_body", "some text");
5. it.putExtra(Intent.EXTRA_STREAM, uri);
6. it.setType("image/png");
7. startActivity(it);
传送 Email
1. Uri uri = Uri.parse("mailto:xxx@abc.com");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. startActivity(it);
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
3. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"me@abc.com"};
3. String[] ccs={"you@abc.com"};
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
7. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
8. it.setType("message/rfc822");
9. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. //传送附件
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
4. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
5. sendIntent.setType("audio/mp3");
6. startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
Uri uri = Uri.parse("file:///sdcard/song.mp3");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
it.setType("audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Market 相关
1. //寻找某个应用
2. Uri uri = Uri.parse("market://search?q=pname:pkg_name");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where pkg_name is the full package path for an application
1. //显示某个应用的相关信息
2. Uri uri = Uri.parse("market://details?id=app_id");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where app_id is the application ID, find the ID
6. //by clicking on your application on Market home
7. //page, and notice the ID from the address bar
Uninstall 应用程序
1. Uri uri = Uri.fromParts("package", strPackageName, null);
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);
1.无参数Activity跳转
Intent it = new Intent(Activity.Main.this, Activity2.class);
startActivity(it);
2.向下一个Activity传递数据(使用Bundle和Intent.putExtras)
Intent it = new Intent(Activity.Main.this, Activity2.class);
Bundle bundle=new Bundle();
bundle.putString("name", "This is from MainActivity!");
it.putExtras(bundle); // it.putExtra(“test”, "shuju”);
startActivity(it); // startActivityForResult(it,REQUEST_CODE);
对于数据的获取可以采用:
Bundle bundle=getIntent().getExtras();
String name=bundle.getString("name");
3.向上一个Activity返回结果(使用setResult,针对startActivityForResult(it,REQUEST_CODE)启动的Activity)
Intent intent=getIntent();
Bundle bundle2=new Bundle();
bundle2.putString("name", "This is from ShowMsg!");
intent.putExtras(bundle2);
setResult(RESULT_OK, intent);
4.回调上一个Activity的结果处理函数(onActivityResult)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE){
if(resultCode==RESULT_CANCELED)
setTitle("cancle");
else if (resultCode==RESULT_OK) {
String temp=null;
Bundle bundle=data.getExtras();
if(bundle!=null) temp=bundle.getString("name");
setTitle(temp);
}
}
}
下面是转载来的其他的一些Intent用法实例(转自javaeye)
显示网页
1. Uri uri = Uri.parse("http://google.com");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
显示地图
1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //其他 geo URI 範例
5. //geo:latitude,longitude
6. //geo:latitude,longitude?z=zoom
7. //geo:0,0?q=my+street+address
8. //geo:0,0?q=business+near+city
9. //google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
路径规划
1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);
4. //where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456
打电话
1. //叫出拨号程序
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_DIAL, uri);
4. startActivity(it);
1. //直接打电话出去
2. Uri uri = Uri.parse("tel:0800000123");
3. Intent it = new Intent(Intent.ACTION_CALL, uri);
4. startActivity(it);
5. //用這個,要在 AndroidManifest.xml 中,加上
6. //<uses-permission id="android.permission.CALL_PHONE" />
传送SMS/MMS
1. //调用短信程序
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. it.putExtra("sms_body", "The SMS text");
4. it.setType("vnd.android-dir/mms-sms");
5. startActivity(it);
1. //传送消息
2. Uri uri = Uri.parse("smsto://0800000123");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. it.putExtra("sms_body", "The SMS text");
5. startActivity(it);
1. //传送 MMS
2. Uri uri = Uri.parse("content://media/external/images/media/23");
3. Intent it = new Intent(Intent.ACTION_SEND);
4. it.putExtra("sms_body", "some text");
5. it.putExtra(Intent.EXTRA_STREAM, uri);
6. it.setType("image/png");
7. startActivity(it);
传送 Email
1. Uri uri = Uri.parse("mailto:xxx@abc.com");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. startActivity(it);
1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
3. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"me@abc.com"};
3. String[] ccs={"you@abc.com"};
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "The email body text");
7. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
8. it.setType("message/rfc822");
9. startActivity(Intent.createChooser(it, "Choose Email Client"));
1. //传送附件
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
4. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
5. sendIntent.setType("audio/mp3");
6. startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
Uri uri = Uri.parse("file:///sdcard/song.mp3");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
it.setType("audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Market 相关
1. //寻找某个应用
2. Uri uri = Uri.parse("market://search?q=pname:pkg_name");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where pkg_name is the full package path for an application
1. //显示某个应用的相关信息
2. Uri uri = Uri.parse("market://details?id=app_id");
3. Intent it = new Intent(Intent.ACTION_VIEW, uri);
4. startActivity(it);
5. //where app_id is the application ID, find the ID
6. //by clicking on your application on Market home
7. //page, and notice the ID from the address bar
Uninstall 应用程序
1. Uri uri = Uri.fromParts("package", strPackageName, null);
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);
发表评论
-
[Android][Activity] onCreate, onSaveInstanceState和onRestoreInstanceState的调用探讨
2011-12-08 16:19 2852(转)http://blog.csdn.net/leewind ... -
android XML转义字符
2011-11-24 19:10 1863在XML中写字符串时,可能需要在字符串后面加空格,A_B(中间 ... -
EditText添加失去焦点事件
2011-11-21 20:29 28966有这样的情况,就是文本框(EditText)会随着某个Butt ... -
Android图片缩放方法
2011-11-21 16:45 843方法1:按固定比例进行 ... -
Activity(Intent)回传数据详解 startActivityForResult()
2011-11-20 12:04 9391startActivityForResult()的用法其实很简 ... -
andriod优秀开源项目
2011-10-19 16:56 1717FBReaderJ FBReaderJ用于Android平台 ... -
Android 应用程序版本
2011-10-19 16:25 783在应用程序的 升级/维护 策略中, 版本是一个关键的组成部分. ... -
[Android UI界面] 连续点击Button,弹出多个Dialog
2011-10-18 19:13 4564首先,你要定义一个全局的Dialog。然后,在点击时间里面判断 ... -
Android webview总结
2011-10-13 14:59 894总结 1.添加权限:AndroidManifest.xml 中 ... -
Android获取IMEI码
2011-10-11 00:07 1563相比大家都知道,每部手机都有一个属于自己的字符串,这个字符串是 ... -
使用Timer定时改变view控件的状态
2011-10-10 22:52 1207//1.声明timer private Timer mTim ... -
Android xml风格和主题
2011-10-08 19:23 933(转)http://www.cnblogs.c ... -
使用全局变量
2011-10-07 10:20 1162如想在整个应用中使用,在java中一般是使用静态变量,而在an ... -
android定义数组
2011-09-09 09:42 13120在android中创建数组,直接定义xml文件即可以。 (1 ... -
Android工程各文件夹结构的含义及使用
2011-09-08 11:06 12280对Android这些东西一开始 ... -
Android解析XML的方式
2011-09-08 10:46 3477android解析xml文件的方式 ... -
android框架
2011-09-07 17:48 651读了高焕堂的书,觉得不错。选点自以为重要的知识,放在这里 ... -
android常识
2011-09-07 15:45 7521.mnt/sdcard和sdcard的区别 其实mnt/sd ... -
使用ViewHolder模式
2011-08-31 14:30 10479ViewHolder不是Android的开发API,而是一种设 ... -
Android SimpleAdapter
2011-08-30 12:28 2260对别人的代码改了一下,主要针对SimpleAdapter做一个 ...
相关推荐
Intent的示例,详细的注释,详细讲解了startActivityForResult的用法,以及Bundle跟Intent保存对象的机制.
主要介绍了Android提高之Activity+Intent用法,是很实用的功能,需要的朋友可以参考下
Intent启动service的示例代码,startService,stopService,bindService.unbindService用法的比较
Intent启动服务的示例代码Intent启动服务的示例代码 startService,stopService,bindService.unbindService用法的比较
代码示例说明Android页面跳转,并且叙述了Activity和Intent的用法原理, 透视分析Bundle类的使用介绍
本文实例讲述了Android编程之桌面小部件AppWidgetProvider用法。分享给大家供大家参考,具体如下: /** * 桌面小部件 AppWidget配置 * * @description: * @author ldm * @date 2016-5-16 下午1:57:16 */ ...
为了将其添加为依赖项,请运行以下命令:$ npm install sentence-intent --save用法示例const sentenceIntent = require ( 'sentence-intent' ) ;const intent = new sentenceIntent ( 'Can you turn up the music?...
本文实例讲述了Android编程图片操作类定义与用法。分享给大家供大家参考,具体如下: 主界面类:拍照及选择相册图片 import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap...
ColorMatrix颜色矩阵的用法.js common(1).js common.js config.js DailyTask.js DensityUtil.js didi.js digit.js dou_yin_yang_hao(1).js dou_yin_yang_hao.js download.js drawBitMap之平移佐罗.js ...
week06-隐含意图 隐含意图 示例代码说明了隐式Intent的用法
5.2 Intent的属性及intent-filter 配置 198 5.2.1 Component属性 198 5.2.2 Action、Category属性与 intent-filter配置 200 5.2.3 指定Action、Category调用 系统Activity 204 5.2.4 Data、Type属性...
本文实例讲述了Android编程实现定时发短信功能。分享给大家供大家参考,具体如下: 第一,要实现发短信的功能,必须要用到android系统中发短信的权限,即在...AlarmManager对象需要配合Intent对象使用,可以定时开启一
SmartScanner Android API 用于便捷API,可简化Intent调用过程。 该库提供了可以用来启动对MRZ,条形码和卡的扫描的方法,而不是手动创建和调用意图的方法。 注意:在达到v1.0之前,库的API可能会不断发展,因此在...
这是一个用法示例: 明天Pwllheli的天气如何? { "intent": "beth.fydd.y.tywydd", "version": 1, "success": true "result": [ { "url": "", "title": "Dyma tywydd yfory gan OpenWeatherMap ar ...
基本用法 命令语法 adb 命令的基本语法如下: adb [-d|-e|-s ] 如果只有一个设备/模拟器连接时,可以省略掉 [-d|-e|-s ] 这一部分,直接使用 adb 。 为命令指定目标设备 如果有多个设备/模拟器连接,则需要为命令...
本文实例讲述了Android基于AlarmManager实现用户在线心跳...AlarmManager对象配合Intent使用,可以定时的开启一个Activity,发送一个BroadCast,或者开启一个Service. 下面的代码详细的介绍了两种定时方式的使用: (1)
一些示例用法 要求用户选择文件夹以保存您的应用文件。 要求用户指向一个文件夹以导入/导出数据。 要求用户从手机存储中选择文件以进行查看,编辑或任何过程。 屏幕截图 可以选择文件夹 可以创建文件夹 也可以...
用法在commanding ,您将提供自然语言短语的示例,这些短语用intent s注释,并且其文本的某些部分用tags. 然后,就像您的示例一样,让commanding任何字符串解析为具有intent和tagged文本的结构化格式。提供例子您...
5.1.2 使用Intent Filter来为隐式Intent提供服务 121 5.1.3 使用Intent Filter作为插件和扩展 129 5.1.4 使用Intent来广播事件 132 5.2 Adapter简介 135 5.2.1 Android提供的部分Adapter简介 135 5.2.2 使用...