本文為 H5EDU 機構官方 HTML5培訓 教程,主要介紹:JavaScript強化教程 —— Native.js示例匯總
Native.js雖然強大和開放,但很多web開發者因為不熟悉原生API而難以獨立完成。
這篇文章的目的就是要總結各種寫好的NJS程式碼,方便web開發者。
眾人拾柴火焰高,有能力的開發者多多提交NJS代碼,大家都會給你點讚的,
Android平台
在桌面創建和刪除App快捷方式
見Hjs 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
強制彈出軟鍵盤
http://ask.dcloud.net.cn/question/2324
取得安卓裝置device.uuid
http://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/8265
NFC資料/ask.dcloud.net.cn/question/6726
截圖
http://ask.dcloud.net.cn/question/5344
取得MAC位址
http://cncloud.MAC地址/question/1511
開啟網路設定
http://ask.dcloud.net.cn/question/1475
開啟位置資訊
http://ask.dcloud.net
開啟位置資訊
http://ask.dcloud.net.取得WIFI清單
http://ask.dcloud.net.cn/question/12113
呼叫系統控製播放影片
http://ask.dcloud.net.cn/question/614
http://ask.dcloud.net.cn/question/614
錄通訊選擇控制
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./cnquestion/5783
http://ask.dcloud.net.//cnquestion/5783
接收系統廣播訊息,如監聽安裝卸載apk的事件
http://ask.dcloud.net.cn/article/222
判斷app是否安裝
http://ask.dcloud.net.net./cn question/7604
以監聽手機飛航模式開關為例說明如何使用Native.js進行BroadcastReceiver廣播
http://ask.dcloud.net.cn/question/7661
實作本地訊息推送(Local Notification)
http://ask.dcloud.net.cn/question/2464
呼叫原生的socket連線
http://ask.dcloud.net.cn/question/60
啟動一個原生service
http://ask.dcloud.net.cn/question/433
停止、開啟個推推推播功能
var pushManager = plus.android.importClass("com.igexin.sd ");
var context = plus.android.runtimeMainActivity();
function enable() {
pushManager.getInstance().turnOnPush(context ). .turnOffPush (context);
}
感謝yeahcheung分享
利用native.js取得手機gps是否開啟
http://ask.dcloud.net.cn/question/11890
://ask.dcloud.net.cn/article/651
iOS平台
取得包名
var NSBundle = plus.ios.importClass('NSBundle');
var bundle .log(bundle.bundleIdentifier());
plus.ios.deleteObject(bundle);
取得裝置名稱
http://ask.dcloud.net.cn/question/14691
http://ask.dcloud.net.cn/question/14691
http://ask.dcloud.net.cn/question/14691
化
。 http://ask.dcloud.net.cn/question/14430
呼叫iOS列印API
http://ask.dcloud.net.cn/question/4226
透過native.jsgamegame 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
播放提示音
ask.dcloud.net.cn/question/3962
呼叫ios的文字轉語音(TTS)
http://ask.dcloud.net.cn/question/4175
把base64資料儲存為圖片://ask.dcloud.net.cn/question/6190
設定webview滑動減速
var webview = plus.ios.currentWebview();
var scrollView = webview.plusGetAttribute("scrollo"); plusSetAttribute("decelerationRate:",0.99);
開啟ios的Wifi設定頁
http://ask.dcloud.net.cn/question/7797
http .net.cn/question/4497 Sharp NSTimeZone = plus.ios.importClass("NSTimeZone");
var sys = NSTimeZone.systemTimeZone();
console.log(sys.plusGetAttribute("name"))); plus.ios.import("UIApplication");
var sharedApplication = UIApplication.sharedApplication();
sharedApplication.setNetworkActivityIndicatorVisible(true);
plus.ios.deleteObject(sharedAppliplus); .ios.import("CLLocationManager");
var authorizationStatus = CLLocationManager.authorizationStatus();
switch(authorizationStatus) {
case 0: application
break;
case 1:
// This application is not authorized to use location services. Due
// to active restrictions on location services, the user ization
break;
case 2 :
// User has explicitly denied authorization for this application, or
// location services are disabled in S.
// User has granted authorization to use their location at any time,
// including monitoring for regions, visits, or significant location changes.
break;
case 4:
. // 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. // This value is deprecated, but was equivalent to the new -Always value.
break;
defalut:
break;
} var
取得手機儲存空間 break;
} var
購買手機儲存空間 j = BundleClass.mainBundle();
var filenamagerobj = plus. ios.newObject("NSFileManager");
var FileAttr = plus.ios.invoke(filenamagerobj,"attributesOfFileSystemForPath:error:",BundleObj.bundlePath(),null);手機總儲存空間
var freeSpace = plus.ios.invoke(FileAttr,"objectForKey:","NSFileSystemFreeSize");
var numberFormatterObj = plus.ios.newObject("NSNumberFormatter"); finoo. (numberFormatterObj,"stringFromNumber:",freeSpace);
var freeSpace = FreeSpaceStr / 1024/1024/1024;
看完這些例子,是不是覺得JS特別強大?
趕快拿去用起來吧!