runtime.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  6. <meta name="HandheldFriendly" content="true"/>
  7. <meta name="MobileOptimized" content="320"/>
  8. <title>Hello H5+</title>
  9. <script type="text/javascript" src="../js/common.js"></script>
  10. <script type="text/javascript">
  11. function getVersion(){
  12. outSet("程序版本名称:"+plus.runtime.version+"\n程序版本号:"+plus.runtime.versionCode+"\n内核版本号:"+plus.runtime.innerVersion+"\nuni-app运行环境:"+plus.runtime.uniVersion);
  13. }
  14. function getArguments(){
  15. outSet("启动方式: "+plus.runtime.launcher+"\n启动参数: "+plus.runtime.arguments);
  16. }
  17. function getChannel(){
  18. outSet("Channel: "+plus.runtime.channel);
  19. }
  20. function restartApp() {
  21. plus.runtime.restart();
  22. }
  23. function getWidgetInfo() {
  24. plus.runtime.getProperty( plus.runtime.appid, function ( wgtinfo ) {
  25. //appid属性
  26. var wgtStr = "appid:"+wgtinfo.appid;
  27. //version属性
  28. wgtStr += "\nversion:"+wgtinfo.version;
  29. wgtStr += "\nversionCode:"+wgtinfo.versionCode;
  30. //name属性
  31. wgtStr += "\nname:"+wgtinfo.name;
  32. //description属性
  33. wgtStr += "\ndescription:"+wgtinfo.description;
  34. //author属性
  35. wgtStr += "\nauthor:"+wgtinfo.author;
  36. //email属性
  37. wgtStr += "\nemail:"+wgtinfo.email;
  38. //features 属性
  39. wgtStr += "\nfeatures:"+wgtinfo.features;
  40. outSet( wgtStr );
  41. } );
  42. }
  43. function setBadge() {
  44. plus.runtime.setBadgeNumber( 50 );
  45. outSet( "设置程序图标右上角显示的提示数字为50\n请返回桌面查看" );
  46. if(plus.os.name=="iOS"){
  47. outLine( '*如果无法设置提示数字,请到"设置"->"通知"中配置应用在通知中心显示!' );
  48. }else{
  49. outLine( "注:仅支持小米(MIUI v5),其它设备暂不支持此功能!" );
  50. }
  51. }
  52. function clearBadge() {
  53. plus.runtime.setBadgeNumber( 0 );
  54. outSet( "清除程序图标右上角显示的提示数字\n请返回桌面查看" );
  55. if(plus.os.name=="iOS"){
  56. outLine( '如果无法清除提示数字,请到"设置"->"通知"中配置应用在通知中心显示!' );
  57. }else{
  58. outLine( "注:仅支持小米(MIUI v5),其它设备暂不支持此功能!" );
  59. }
  60. }
  61. function exitApp(){
  62. if(plus.os.name=="Android"){
  63. plus.runtime.quit();
  64. }else{
  65. outSet( "此平台不支持直接退出程序,请按Home键切换应用" );
  66. }
  67. }
  68. function updateApp(){
  69. var url='http://demo.dcloud.net.cn/helloh5/update/HelloH5.wgtu';
  70. plus.nativeUI.showWaiting("升级中...");
  71. var dtask = plus.downloader.createDownload( url, {method:"GET"}, function(d,status){
  72. if ( status == 200 ) {
  73. console.log( "Download wgtu success: " + d.filename );
  74. plus.runtime.install(d.filename,{},function(){
  75. plus.nativeUI.closeWaiting();
  76. plus.nativeUI.alert("Update wgtu success, restart now!",function(){
  77. plus.runtime.restart();
  78. });
  79. },function(e){
  80. plus.nativeUI.closeWaiting();
  81. alert("Update wgtu failed: "+e.message);
  82. });
  83. } else {
  84. plus.nativeUI.closeWaiting();
  85. alert( "Download wgtu failed: " + status );
  86. }
  87. } );
  88. dtask.addEventListener('statechanged',function(d,status){
  89. console.log("statechanged: "+d.state);
  90. });
  91. dtask.start();
  92. }
  93. </script>
  94. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
  95. </head>
  96. <body>
  97. <br/>
  98. <div class="button" onclick="clicked('runtime_launch.html',true);">
  99. 调用第三方程序
  100. </div>
  101. <br/>
  102. <ul class="dlist">
  103. <li class="ditem" onclick="getVersion()">获取版本信息</li>
  104. <li class="ditem" onclick="getArguments()">获取启动信息</li>
  105. <li class="ditem" onclick="getChannel()">获取渠道信息</li>
  106. <li class="ditem" onclick="restartApp()">重启当前应用</li>
  107. <li class="ditem" onclick="getWidgetInfo()">获取当前应用的基本属性</li>
  108. <li class="ditem" onclick="setBadge()">设置程序图标右上角数字</li>
  109. <li class="ditem" onclick="clearBadge()">清除程序图标右上角数字</li>
  110. <li class="ditem" onclick="exitApp()">退出当前应用</li>
  111. <!--li class="ditem" onclick="updateApp()">WGTU Update</li-->
  112. </ul>
  113. <div id="outpos"/>
  114. <div id="output">
  115. Runtime管理程序运行时环境,可用于获取程序的各种信息、与第三方程序通讯等。
  116. </div>
  117. </body>
  118. </html>