android教程之intent的action属性使用示例(intent发短信)
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 RecyclerView网格布局(支持多种分割线)详解(2)
这篇文章主要为大家详细介绍了Android RecyclerView网格布局,支持多种分割线,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-02-02
Android开发之ContentProvider的使用详解
本篇文章介绍了Android开发之ContentProvider的使用详解。需要的朋友参考下2013-04-04
新浪微博第三方登录界面上下拉伸图片之第三方开源PullToZoomListViewEx(二)
这篇文章主要介绍了新浪微博第三方登录界面上下拉伸图片之第三方开源PullToZoomListViewEx(二) 的相关资料,需要的朋友可以参考下2015-12-12
详解如何在Android studio中更新sdk版本和build-tools版本
这篇文章主要介绍了如何在Android studio中更新sdk版本和build-tools版本,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-11-11
item高度不同时Recyclerview获取滑动距离的方法
这篇文章主要介绍了item高度不同时Recyclerview获取滑动距离的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-11-11


最新评论