android教程之intent的action属性使用示例(intent发短信)
2016-09-19 21:57
316 查看
Action :规定了Intent要完成的动作,是一个字符串常量。使用setAction()来设置Action属性,使用getAction()来获得Action属性。既可以使用系统内置的Action,也可以自己定义。系统自定义的action,如ACTION_VIEW, ACTION_EDIT, ACTION_MAIN等等。
1.自定义Action
在“目的Activity”的AndroidManifest.xml中指定action常量。
复制代码 代码如下:
<activity android:name=".ActionDestination">
<intent-filter>
<action android:name="Skywang_ACTION" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<categoryandroid:name="android.intent.category.DEFAULT" />的作用是用来说明,可以通过隐式跳转(即其它类调用setAction("Skywang_ACTION"))来找到ActionDestination这个activity。这样,其它的类就可以通过下面的代码跳转到ActionDestination。跳转时,setAction的字符串"Skywang_ACTION"必须与AndroidManifest.xml中定义的"Skywang_ACTION"一致。
复制代码 代码如下:
Intent intent = new Intent();
intent.setAction("Skywang_ACTION");
startActivity(intent);
2系统Action
复制代码 代码如下:
// 流量网页
Uri uri =Uri.parse("http://www.baidu.com");
Intent intent = newIntent(Intent.ACTION_VIEW, uri);
startActivity(intent);
// 拨打电话
// if you want to use ACTION_DIAL, you mustadd permissin in manifest, the permission is bellow
// <uses-permissionandroid:name="android.permission.CALL_PHONE" />
Uri uri = Uri.parse("tel:12580");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
// 发送短信
Uri uri = Uri.parse("smsto:13410177756");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
//播放mp3
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
1.自定义Action
在“目的Activity”的AndroidManifest.xml中指定action常量。
复制代码 代码如下:
<activity android:name=".ActionDestination">
<intent-filter>
<action android:name="Skywang_ACTION" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<categoryandroid:name="android.intent.category.DEFAULT" />的作用是用来说明,可以通过隐式跳转(即其它类调用setAction("Skywang_ACTION"))来找到ActionDestination这个activity。这样,其它的类就可以通过下面的代码跳转到ActionDestination。跳转时,setAction的字符串"Skywang_ACTION"必须与AndroidManifest.xml中定义的"Skywang_ACTION"一致。
复制代码 代码如下:
Intent intent = new Intent();
intent.setAction("Skywang_ACTION");
startActivity(intent);
2系统Action
复制代码 代码如下:
// 流量网页
Uri uri =Uri.parse("http://www.baidu.com");
Intent intent = newIntent(Intent.ACTION_VIEW, uri);
startActivity(intent);
// 拨打电话
// if you want to use ACTION_DIAL, you mustadd permissin in manifest, the permission is bellow
// <uses-permissionandroid:name="android.permission.CALL_PHONE" />
Uri uri = Uri.parse("tel:12580");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
// 发送短信
Uri uri = Uri.parse("smsto:13410177756");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
//播放mp3
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
相关文章推荐
- android教程之intent的action属性使用示例(intent发短信)
- Android使用Intent.ACTION_SEND分享图片和文字内容的示例代码
- android组件通讯 Intent-Action属性
- Android中级教程(二)之调用另一个Activity---Intent对象的使用!
- 【Android 开发教程】使用Intent传递数据
- android Intent的Action、Category属性
- Android中属性动画Property Animation使用示例(四)
- 【Android 开发教程】使用Intent发送短信
- Android自定义属性的使用示例
- 【Android 开发教程】使用IntentService执行异步操作
- Android开发之Intent.Action 各个属性说明
- android开发教程之使用线程实现视图平滑滚动示例
- phonegap 开发入门 PhoneGap官方网站上有详细的入门示例教程,这里,我针对使用PhoneGap进行Android移动应用的开发对其官网的Get Started进行一些介绍、补充。 Ste
- 【Android 开发教程】使用Intent-Filter
- [置顶] 调用Android发短信接口Intent.ACTION_SENDTO
- Android中级教程(二)之调用另一个Activity---Intent对象的使用!
- Android 程式开发:(四)使用Intent调用“内置”应用 —— 4.4添加Category属性
- Android中的Intent原理,属性和使用方法
- android Intent.ACTION使用
- android教程之service使用方法示例详解