本文爲 H5EDU 機構官方 HTML5培訓 教程,主要介紹:JavaScript強化教程 —— Native.js示例彙總
html
Native.js雖然強大和開放,但不少web開發者由於不熟悉原生API而難以獨立完成。 這篇帖子的目的就是彙總各類寫好的NJS代碼,方便web開發者。 衆人拾柴火焰高,有能力的開發者多多提交NJS代碼,你們都會給你點讚的,
Android平臺 在桌面建立和刪除App快捷方式 見Hello H5+裏Native.js部分演示及源碼。 或在這裏搜索「快捷方式」,http://ask.dcloud.net.cn/docs/ ... le/88調用Android本地分享http://ask.dcloud.net.cn/article/134直接撥打電話http://ask.dcloud.net.cn/question/4035將程序切換到後臺http://ask.dcloud.net.cn/question/2484強制彈出軟鍵盤http://ask.dcloud.net.cn/question/2324獲取安卓設備device.uuidhttp://ask.dcloud.net.cn/question/3510獲取內存及CPU信息http://ask.dcloud.net.cn/question/2202開啓關閉藍牙http://ask.dcloud.net.cn/question/4720監聽藍牙開關狀態http://ask.dcloud.net.cn/article/274獲取藍牙設備列表http://ask.dcloud.net.cn/question/8265NFC數據讀取http://ask.dcloud.net.cn/question/6726截屏http://ask.dcloud.net.cn/question/5344獲取MAC地址http://ask.dcloud.net.cn/question/1511打開網絡設置http://ask.dcloud.net.cn/question/1475打開位置信息http://ask.dcloud.net.cn/question/14731獲取WIFI列表http://ask.dcloud.net.cn/question/12113調用系統控件播放視頻http://ask.dcloud.net.cn/question/614調用os通信錄選擇控件http://ask.dcloud.net.cn/question/5783原生日曆提醒插入http://ask.dcloud.net.cn/article/215調用系統控件裁剪圖片http://ask.dcloud.net.cn/question/8314複製內容到系統粘貼板http://ask.dcloud.net.cn/question/2034調用訊飛的文字轉語音功能(TTS)http://ask.dcloud.net.cn/question/6473調用其它Activity後經過startActivityForResult獲取返回結果http://ask.dcloud.net.cn/question/5783接收系統廣播消息,如監聽安裝卸載apk的事件http://ask.dcloud.net.cn/article/222判斷app是否安裝http://ask.dcloud.net.cn/question/7604以×××飛行模式開關爲例說明如何使用Native.js進行BroadcastReceiver廣播http://ask.dcloud.net.cn/question/7661常駐Android通知欄,不用個推實現本地消息推送(Local Notification)http://ask.dcloud.net.cn/question/2464調用原生的socket鏈接http://ask.dcloud.net.cn/question/60啓動一個原生servicehttp://ask.dcloud.net.cn/question/433中止、開啓個推推送功能 var pushManager = plus.android.importClass("com.igexin.sdk.PushManager"); var context = plus.android.runtimeMainActivity(); function enable() { pushManager.getInstance().turnOnPush(context); } function disable() { pushManager.getInstance().turnOffPush(context); } 感謝yeahcheung分享 利用native.js獲取手機gps是否開啓http://ask.dcloud.net.cn/question/11890經過native.js設置系統牆紙http://ask.dcloud.net.cn/article/651iOS平臺 獲取包名 var NSBundle = plus.ios.importClass('NSBundle'); var bundle = NSBundle.mainBundle(); console.log(bundle.bundleIdentifier()); plus.ios.deleteObject(bundle); 獲取設備名http://ask.dcloud.net.cn/question/14691測試是否安裝某應用http://ask.dcloud.net.cn/question/14430調用iOS打印APIhttp://ask.dcloud.net.cn/question/4226經過native.js登入game center 見Hello H5+裏Native.js部分演示及源碼。 或在這裏搜索「game center」,http://ask.dcloud.net.cn/docs/ ... le/88設置獲取內容到系統粘貼板http://ask.dcloud.net.cn/question/3720打開頁面默認彈出鍵盤http://ask.dcloud.net.cn/question/2324播放提示音http://ask.dcloud.net.cn/question/3962調用ios的文字轉語音(TTS)http://ask.dcloud.net.cn/question/4175把base64數據保存爲圖片http://ask.dcloud.net.cn/question/6190設置webview滑動減速度 var webview = plus.ios.currentWebview(); var scrollView = webview.plusGetAttribute("scrollView"); scrollView.plusSetAttribute("decelerationRate:",0.99); 打開ios的Wifi設置頁面http://ask.dcloud.net.cn/question/7797判斷是否開啓消息通知http://ask.dcloud.net.cn/question/4497檢測iOS是否容許使用相機(感謝小鬧分享)http://ask.dcloud.net.cn/article/188ios獲取系統的時區id var NSTimeZone = plus.ios.importClass("NSTimeZone"); var sys = NSTimeZone.systemTimeZone(); console.log(sys.plusGetAttribute("name")); 狀態欄顯示網絡請求雪花 var UIApplication = plus.ios.import("UIApplication"); var sharedApplication = UIApplication.sharedApplication(); sharedApplication.setNetworkActivityIndicatorVisible(true); plus.ios.deleteObject(sharedApplication); 獲取GPS受權狀態 var CLLocationManager = plus.ios.import("CLLocationManager"); var authorizationStatus = CLLocationManager.authorizationStatus(); switch(authorizationStatus) { case 0: /// User has not yet made a choice with regards to this application break; case 1: // This application is not authorized to use location services. Due // to active restrictions on location services, the user cannot change // this status, and may not have personally denied authorization break; case 2: // User has explicitly denied authorization for this application, or // location services are disabled in Settings. break; case 3: // User has granted authorization to use their location at any time, // including monitoring for regions, visits, or significant location changes. break; case 4: // User has granted authorization to use their location only when your app // is visible to them (it will be made visible to them if you continue to // receive location updates while in the background). Authorization to use // launch APIs has not been granted. break; case 5: // This value is deprecated, but was equivalent to the new -Always value. break; defalut: break; } 獲取手機存儲空間 var BundleClass = plus.ios.importClass("NSBundle"); var BundleObj = BundleClass.mainBundle(); var filenamagerobj = plus.ios.newObject("NSFileManager"); var FileAttr = plus.ios.invoke(filenamagerobj,"attributesOfFileSystemForPath:error:",BundleObj.bundlePath(),null); // NSFileSystemFreeSize 參數獲取剩餘空間 // NSFileSystemSize 獲取手機總存儲空間 var freeSpace = plus.ios.invoke(FileAttr,"objectForKey:","NSFileSystemFreeSize"); var numberFormatterObj = plus.ios.newObject("NSNumberFormatter"); var FreeSpaceStr = plus.ios.invoke(numberFormatterObj,"stringFromNumber:",freeSpace); var freeSpace = FreeSpaceStr / 1024/1024/1024; 看完這些例子,是否是以爲JS特別強大? 趕快拿去用起來吧!
點擊進入JS強化教程
android