android Intent用法实例(1)
2013-11-21 16:02
387 查看
ACTION_MAIN 应用程序入口
ACTION_VIEW 显示指定数据
ACTION_DIAL 显示拨号面板ACTION_CALL 直接向指定用户打电话
ACTION_SENDTO 向其他人发送消息
ACTION_SEND 向其他人发送数据
ACTION_DELETE 删除数据
ACTION_MAIN 应用程序入口
[b]返回桌面[/b]Intent it = new Intent(Intent.ACTION_MAIN); it.addCategory(Intent.CATEGORY_HOME); startActivity(it);
[b]ACTION_VIEW 显示指定数据
[/b]
显示网页
Uri uri = Uri.parse("http://www.baidu.com"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
播放多媒体
Uri uri = Uri.parse("file:///sdcard/song.mp3"); Intent it = new Intent(Intent.ACTION_VIEW); it.setDataAndType(uri, "video/mp3"); startActivity(it);
ACTION_DIAL 显示拨号面板
ACTION_CALL 直接向指定用户打电话
打电话
//叫出拨号程序 Uri uri = Uri.parse("tel:10086"); Intent it = new Intent(Intent.ACTION_DIAL, uri); startActivity(it); //直接打电话出去 Uri uri = Uri.parse("tel:10086"); Intent it = new Intent(Intent.ACTION_CALL, uri); startActivity(it); //权限 //<uses-permission id="android.permission.CALL_PHONE" />
ACTION_SENDTO 向其他人发送消息
ACTION_SEND 向其他人发送数据
[b]发送SMS/MMS[/b]
//调用短信程序 Intent it = new Intent(Intent.ACTION_VIEW); it.putExtra("sms_body", "The SMS text"); it.setType("vnd.android-dir/mms-sms"); startActivity(it); //发送消息 Uri uri = Uri.parse("smsto://10086"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", "The SMS text"); startActivity(it); //发送 MMS Uri uri = Uri.parse("content://media/external/images/media/23"); Intent it = new Intent(Intent.ACTION_SEND); it.putExtra("sms_body", "some text"); //uri 可以是你从手机相册中得到图片的地址,取手机相册图片可以参考Intent.ACTION_PICK或Intent.ACTION_GET_CONTENT it.putExtra(Intent.EXTRA_STREAM, uri); it.setType("image/*"); startActivity(it);
传送 Email
Uri uri = Uri.parse("mailto:xxx@abc.com"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); startActivity(it); Intent it = new Intent(Intent.ACTION_SEND); //我在测试时发现 ACTION_SEND指定地址时不起作用?有大神看到的话,还请赐教 it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com"); it.putExtra(Intent.EXTRA_TEXT, "The email body text"); it.setType("text/plain"); startActivity(Intent.createChooser(it, "Choose Email Client")); Intent it=new Intent(Intent.ACTION_SEND); String[] tos={"me@abc.com"}; //收件人 String[] ccs={"you@abc.com"}; //抄送 it.putExtra(Intent.EXTRA_EMAIL, tos); it.putExtra(Intent.EXTRA_CC, ccs); it.putExtra(Intent.EXTRA_TEXT, "The email body text"); it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); it.setType("message/rfc822"); startActivity(Intent.createChooser(it, "Choose Email Client")); //传送附件 Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); //把地址改成你从手机里取到的地址(data.getData()一个URI) it.putExtra(Intent.EXTRA_STREAM, data.getData()); it.setType("audio/mp3"); startActivity(Intent.createChooser(it, "Choose Email Client"));
ACTION_DELETE 删除数据
[b]Uninstall 应用程序
[/b]
Uri uri = Uri.fromParts("package", "包名", null); Intent it = new Intent(Intent.ACTION_DELETE, uri); startActivity(it)
相关文章推荐
- Android深入浅出系列之实例应用—开机就运行自定义的程序BroadcastReceiver和intent-filter的用法
- Android Activity和Intent用法实例
- android中部分Intent用法实例
- Android Intent 用法全面总结及实例代码
- Android深入浅出系列之实例应用—开机就运行自定义的程序BroadcastReceiver和intent-filter的用法
- Android:intent用法实例
- Android深入浅出系列之实例应用—开机就运行自定义的程序BroadcastReceiver和intent-filter的用法
- android的Intent用法实例
- android的Intent用法实例
- Android Intent 用法全面总结及实例代码
- Android学习之Intent中显示意图和隐式意图的用法实例分析
- android之Intent几个基础用法示例
- Android中GPS定位的用法实例
- Android开发之Animations动画用法实例详解
- Android开发--Intent的用法小结
- Android Intent 常见用法总结
- Android中SurfaceView用法简单实例
- Android Intent的几种用法全面总结
- Android Intent用法详解
- Android开发中Intent用法总结