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

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

概述Action:规定了Intent要完成的动作,是一个字符串常量。使用setAction()来设置Action属性,使用getAction()来获得Action属性。既可以使用系统内置的Action,也可以自己定义。系统自定义的action,如ACTION_VIEW,ACTI

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属性使用示例(intent发短信)全部内容,希望文章能够帮你解决android教程之intent的action属性使用示例(intent发短信)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1141602.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存