联想序列号查询入口(联想电脑官网查询真伪入口)

android项目完成后,未来所有的pad设备都需要在springboot服务后端进行监控。那么这个时候就需要一个保活机制,让服务器实时监控所有pad设备的工作

android项目完成后,未来所有的pad设备都需要在springboot服务后端进行监控。那么这个时候就需要一个保活机制,让服务器实时监控所有pad设备的工作状态。

联想序列号查询入口(联想电脑官网查询真伪入口)

实现思路:每台设备都有唯一的s/n序列号,我们可以在android上做一个服务,或者,a。

Timer每隔几秒发送一次包含sn序列号的保活数据,并将其提供给服务器,让服务器了解该设备。

是的,状态是可用。如果服务器长时间没有收到设备的保活信息,证明设备可能已经关机,或者

我们的软件没有运行,或者设备出了故障。

1.我们先来看看如何获取设备的序列号。这种采集方式每个设备都不一样,比如华为平板的S/N。

这种方式无法解决,我们用联想肖鑫Pad:是的:

try { final String serial nostr = & # 34;[ro . ODM . Lenovo . gsn]& # 34;;Process p = Runtime.getRuntime()。exec(& # 34;getprop & # 34);p . wait for();buffered reader stdInput = new buffered reader(new InputStreamReader(p . getinputstream()));String temp = & # 34";while ((temp = stdInput.readLine())!= null){ if(temp . contains(serial nostr)){ temp . replace all(& # 34;", "");int index = temp . index of(serial nostr);temp = temp . substring(index+20);temp = temp.substring(1,temp . length()-1);log . d(& # 34;getSerialnoNumbers & # 34,temp);temp = temp . replace all(& # 34;\[","");//1.首先,获得联想肖鑫pad的序列号。//2.然后将序列号保存在配置文件中:unique _ sn saveConfigValue(& # 34;unique _ sn & # 34,string . value of(temp));//3.然后,我们到配置文件中获取序列号,看看是否有序列号。如果有,则获取的//序列号串sn = getConfigValue。getConfigProperties(& # 34;unique _ sn & # 34);if(string utils . isnotempty(sn)){ toast . make text(this,& # 34;当前设备序列号为:& # 34;+sn,吐司。长度_长)。show();//toastutils . toast(commonsettingactivity . this,& # 34;当前设备序列号为:& # 34;+sn);}else{ //4。如果没有序列号,会弹出找到的序列号,然后将序列号保存在配置文件//5中。然后找到的序列号会弹出//snowlakeidworker id worker = new snowlakeidworker(1,0);//long snum = id worker . nextid();saveConfigValue(& # 34;unique _ sn & # 34,string . value of(temp));Toast.makeText(this,& # 34;当前设备序列号为:& # 34;+String.valueOf(temp),Toast。长度_长)。show();//toastutils . toast(commonsettingactivity . this,& # 34;当前设备序列号为:& # 34;+string . value of(snum));}//Message msg = new Message();//msg . obj = temp;//mhandler . sendmessage(msg);打破;} else { log . d(& # 34;getserial nonumbers 1:& # 34;,temp);} }

2.如果通过上面的方法没有找到序列号,说明它不是联想肖鑫的pad,那么这个时候,我们可以自己使用它。

Snow算法,获取一个设备代码:这保证了所有的设备都有自己的设备代码,因为在这里,我们的项目要求。

统一使用,联想肖鑫pad,所以不存在,序列号找不到,这里是保守逻辑。

If(字符串实用程序。isempty (temp)) {//1。转到配置文件获取序列号,字符串sn = getConfigValue。getConfigProperties(& # 34;unique _ sn & # 34);If(字符串实用程序。不为空(sn)) {//2。如果获得了序列号,Toast.makeText(this,& # 34;当前设备序列号为:& # 34;+sn,吐司。长度_长)。show();//toastutils . toast(commonsettingactivity . this,& # 34;当前设备序列号为:& # 34;+sn);}else{//3。如果没有获得序列号,生成一个,然后保存,然后显示。snowlakeidworker id worker = new snowlakeidworker(1,0);long snum = id worker . nextid();saveConfigValue(& # 34;unique _ sn & # 34,string . value of(snum));Toast.makeText(this,& # 34;当前设备序列号为:& # 34;+String.valueOf(snum),Toast。长度_长)。show();//toastutils . toast(commonsettingactivity . this,& # 34;当前设备序列号为:& # 34;+string . value of(snum));} }

3.上面使用的并保存在配置文件中的工具和方法再次发布在这里。之前有关于配置文件使用的文章。

从配置文件中获取值:

包com . Baidu . IDL . main . faces dk . utils;导入Java . io . file;导入Java . io . file inputstream;导入Java . io . inputstream;导入Java . util . properties;公共类GetConfigValue { public static boolean isfile exists = false;公共静态属性props = new Properties();公共静态字符串getConfigProperties(String key){ String result = & # 34;";尝试{ String configPath = & # 34/data/data/com . Baidu . IDL . face . demo/audio file/config . properties & # 34;;File file =新文件(config path);if(file . exists()){ isfile exists = true;} else { isFileExists = false结果= & # 34;noFile & # 34;返回结果;}//初始化配置文件字符串configValue = & # 34";InputStream InputStream = new file InputStream(config path);props . load(inputStream);config value = props . getproperty(key);返回configValue} catch(异常E1){ E1 . printstacktrace();return & # 34例外& # 34;;}最终{ } }

4.然后保存文件:

//修改属性文件私有字符串saveconfigvalue (string key,string value){ try { copy dbfile(commonsettingactivity。这个,& # 34;config.properties & # 34);String configPath = & # 34/data/data/& # 34;+commonsettingactivity . this . get package name()+& # 34;/audio file/config . properties & # 34;;InputStream InputStream = new file InputStream(config path);//初始化配置文件Propels = new properties();props . load(inputStream);props.setProperty(key,value);File file =新文件(config path);output stream fos = new file output stream(file);props.store(fos,& # 34;更新& # 39;"+key+& # 34;'价值& # 34;);fos . flush();返回值;} catch(异常E1){ toastutils . toast(commonsettingactivity . this,& # 34;无法保存配置信息& # 34;);return & # 34-1";}最终{ } }

5.以上代码可以根据自己的需要稍加修改。下面是上面代码中需要的方法。

private void copyDbFile(Context上下文,字符串文件名){ InputStream in = nullFileOutputStream out = null字符串路径= & # 34;/data/data/& # 34;+context . get package name()+& # 34;/audio file/& # 34;;File file =新文件(路径+文件名);//创建文件夹file path = new file(path);如果(!file path . exists())file path . mkdirs();if (file.exists())返回;请尝试{ in = context.getAssets()。打开(文件名);//从资产目录中copy out = new file output stream(file );int length =-1;byte[] buf =新字节[1024];while ((length = in.read(buf))!= -1) { out.write(buf,0,length);} out . flush();} catch(Exception e){ e . printstacktrace();}最后{试试{如果(在!= null)in . close();如果(出!= null)out . close();} catch(io exception E1){ E1 . printstacktrace();} } }

6.然后在上面的部分,获取序列号后,在保活的时候,只需要将序列号发送到springboot服务器进行验证即可。在这里,可以使用okhttpclient来发送请求,也可以使用Android native HttpURLConnection。

您可以启动服务并每隔几秒发送一次保活信息,也可以使用计时器发送保活信息。

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。

作者:美站资讯,如若转载,请注明出处:https://www.meizw.com/n/402806.html

发表回复

登录后才能评论