您好,登錄后才能下訂單哦!
為大家分享一些android公共方法native.js實現代代碼,如獲取手機MAC地址,手機內存大小,手機存儲空間大小,手機CPU信息等手機硬件基本信息
native.js獲取手機MAC地址
/*得到手機MAC地址*/ function getMac() { var mac = "xxx-xxx-xxx-xxx"; if (plus.os.name == "Android") { //WifiManager var Context = plus.android.importClass("android.content.Context"); var WifiManager = plus.android.importClass("android.net.wifi.WifiManager"); var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE); var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo"); var wifiInfo = wifiManager.getConnectionInfo(); mac = wifiInfo.getMacAddress(); } return mac; }
native.js獲取手機內存信息
/*獲取手機內存信息*/ function getMemorySize() { var memoryInfo = ''; if (plus.os.name == "Android") { var Context = plus.android.importClass("android.content.Context"); var ActivityManager = plus.android.importClass("android.app.ActivityManager"); var mi = new ActivityManager.MemoryInfo(); var activityService = plus.android.runtimeMainActivity().getSystemService(Context.ACTIVITY_SERVICE); activityService.getMemoryInfo(mi); memoryInfo = mi.plusGetAttribute("availMem"); } return memoryInfo; }
native.js獲取手機內部總的存儲空間
/*獲取手機內部總的存儲空間*/ function getTotalInternalMemorySize() { var internalMemSize = 0; if (plus.os.name == "Android") { var environment = plus.android.importClass("android.os.Environment"); var statFs = plus.android.importClass("android.os.StatFs"); var files = plus.android.importClass("java.io.File"); var Files = environment.getDataDirectory(); var StatFs = new statFs(Files.getPath()); var blockSize = parseFloat(StatFs.getBlockSize()); var blockCount = parseFloat(StatFs.getBlockCount()); internalMemSize = blockSize * blockCount; } return internalMemSize; }
native.js獲取手機總內存
/*獲取總內存*/ function getTotalRamSize() { var memInfo = '/proc/meminfo'; var temp = '', ramSize = '', arrays, initMemory; var fileReader = plus.android.importClass("java.io.FileReader"); var bufferedReader = plus.android.importClass("java.io.BufferedReader"); var FileReader = new fileReader(memInfo); var BufferedReader = new bufferedReader(FileReader, 8192); while ((temp = BufferedReader.readLine()) != null) { if (-1 != temp.indexOf('MemTotal:')) { var value = temp.replace(/[^0-9]/ig, ""); ramSize = Math.floor(parseInt(value) / (1024)); } } return ramSize; }
native.js獲取手機CPU信息
/*獲取手機CPU信息*/ function getCpuInfo() { var cpuInfo = '/proc/cpuinfo'; var temp = '', cpuHardware; var fileReader = plus.android.importClass("java.io.FileReader"); var bufferedReader = plus.android.importClass("java.io.BufferedReader"); var FileReader = new fileReader(cpuInfo); var BufferedReader = new bufferedReader(FileReader, 8192); while ((temp = BufferedReader.readLine()) != null) { if (-1 != temp.indexOf('Hardware')) { cpuHardware = temp.substr(parseInt(temp.indexOf(":")) + 1); } } return cpuHardware; }
native.js獲取CPU核數
/*獲取CPU核數*/ function getCpuCount() { var Runtime = plus.android.importClass("java.lang.Runtime"); var cpuCount = Runtime.getRuntime().availableProcessors(); return cpuCount; }
native.js 獲取安卓設備的ANDROID_ID
var mainActivity = plus.android.runtimeMainActivity(); var Settings= plus.android.importClass("android.provider.Settings"); console.log(Settings.Secure.getString(mainActivity.getContentResolver(),Settings.Secure.ANDROID_ID));
附Dcloud的Native.js支持的API詳細介紹與說明
www.dcloud.io/docs/api/index.html
獲取更多關于native.js獲取手機硬件基本信息實例代碼內容請查看下面相關鏈接
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。