native.js获取手机硬件基本信息实例代码android版
程序员文章站
2022-06-19 19:53:38
为大家分享一些android公共方法native.js实现代代码,如获取手机mac地址,手机内存大小,手机存储空间大小,手机cpu信息等手机硬件基本信息
native.j...
为大家分享一些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详细介绍与说明
获取更多关于native.js获取手机硬件基本信息实例代码内容请查看下面相关链接
下一篇: 抖音识图怎么玩 抖音识图功能使用教程