iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >android教程之intent的action属性使用示例(intent发短信)
  • 685
分享到

android教程之intent的action属性使用示例(intent发短信)

示例intentactionAndroid 2022-06-06 10:06:23 685人浏览 安东尼
摘要

Action :规定了Intent要完成的动作,是一个字符串常量。使用setAction()来设置Action属性,使用getAction()来获得Action属性。既可以使用

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);

您可能感兴趣的文章:Android使用Intent.ACTION_SEND分享图片和文字内容的示例代码Android编程实现自定义分享列表ACTION_SEND功能的方法android中Intent传值与Bundle传值的区别详解android中intent传递list或者对象的方法Android Intent的几种用法详细解析Android 广播大全 Intent Action 事件详解详解Android中IntentService的使用方法Android中使用IntentService创建后台服务实例Android利用Intent.ACTION_SEND进行分享


--结束END--

本文标题: android教程之intent的action属性使用示例(intent发短信)

本文链接: https://www.lsjlt.com/news/27202.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作