Android Intent应用,打开网页,安装程序,打电话,打开地图等功能

本文提供了多个 Android Intent 的使用案例,包括启动浏览器、地图导航、拨打电话、发送短信和邮件等常见功能的实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[java] view plain copy
  1. 1.从google搜索内容
  2. Intentintent=newIntent();
  3. intent.setAction(Intent.ACTION_WEB_SEARCH);
  4. intent.putExtra(SearchManager.QUERY,"searchString")
  5. startActivity(intent);
  6. 2.浏览网页
  7. Uriuri=Uri.parse("http://www.google.com");
  8. Intentit=newIntent(Intent.ACTION_VIEW,uri);
  9. startActivity(it);
  10. 3.显示地图
  11. Uriuri=Uri.parse("geo:38.899533,-77.036476");
  12. Intentit=newIntent(Intent.Action_VIEW,uri);
  13. startActivity(it);
  14. 4.路径规划
  15. Uriuri=Uri.parse("http://maps.google.com/maps?f=dsaddr=startLatstartLng&daddr=endLatendLng&hl=en");
  16. Intentit=newIntent(Intent.ACTION_VIEW,URI);
  17. startActivity(it);
  18. 5.拨打电话
  19. Uriuri=Uri.parse("tel:xxxxxx");
  20. Intentit=newIntent(Intent.ACTION_DIAL,uri);
  21. startActivity(it);
  22. 6.调用发短信的程序
  23. Intentit=newIntent(Intent.ACTION_VIEW);
  24. it.putExtra("sms_body","TheSMStext");
  25. it.setType("vnd.android-dir/mms-sms");
  26. startActivity(it);
  27. 7.发送短信
  28. Uriuri=Uri.parse("smsto:0800000123");
  29. Intentit=newIntent(Intent.ACTION_SENDTO,uri);
  30. it.putExtra("sms_body","TheSMStext");
  31. startActivity(it);
  32. Stringbody="thisissmsdemo";
  33. Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts("smsto",number,null));
  34. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
  35. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);
  36. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);
  37. startActivity(mmsintent);
  38. 8.发送彩信
  39. Uriuri=Uri.parse("content://media/external/images/media/23");
  40. Intentit=newIntent(Intent.ACTION_SEND);
  41. it.putExtra("sms_body","sometext");
  42. it.putExtra(Intent.EXTRA_STREAM,uri);
  43. it.setType("image/png");
  44. startActivity(it);
  45. StringBuildersb=newStringBuilder();
  46. sb.append("file://");
  47. sb.append(fd.getAbsoluteFile());
  48. Intentintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts("mmsto",number,null));
  49. //Belowextradatasarealloptional.
  50. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);
  51. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
  52. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());
  53. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);
  54. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);
  55. startActivity(intent);
  56. 9.发送Email
  57. Uriuri=Uri.parse("mailto:xxx@abc.com");
  58. Intentit=newIntent(Intent.ACTION_SENDTO,uri);
  59. startActivity(it);
  60. Intentit=newIntent(Intent.ACTION_SEND);
  61. it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");
  62. it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
  63. it.setType("text/plain");
  64. startActivity(Intent.createChooser(it,"ChooseEmailClient"));
  65. Intentit=newIntent(Intent.ACTION_SEND);
  66. String[]tos={"me@abc.com"};
  67. String[]ccs={"you@abc.com"};
  68. it.putExtra(Intent.EXTRA_EMAIL,tos);
  69. it.putExtra(Intent.EXTRA_CC,ccs);
  70. it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
  71. it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
  72. it.setType("message/rfc822");
  73. startActivity(Intent.createChooser(it,"ChooseEmailClient"));
  74. Intentit=newIntent(Intent.ACTION_SEND);
  75. it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
  76. it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
  77. sendIntent.setType("audio/mp3");
  78. startActivity(Intent.createChooser(it,"ChooseEmailClient"));
  79. 10.播放多媒体
  80. Intentit=newIntent(Intent.ACTION_VIEW);
  81. Uriuri=Uri.parse("file:///sdcard/song.mp3");
  82. it.setDataAndType(uri,"audio/mp3");
  83. startActivity(it);
  84. Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
  85. Intentit=newIntent(Intent.ACTION_VIEW,uri);
  86. startActivity(it);
  87. 11.卸载apk
  88. Uriuri=Uri.fromParts("package",strPackageName,null);
  89. Intentit=newIntent(Intent.ACTION_DELETE,uri);
  90. startActivity(it);
  91. 12.安装apk
  92. UriinstallUri=Uri.fromParts("package","xxx",null);
  93. returnIt=newIntent(Intent.ACTION_PACKAGE_ADDED,installUri);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值