Android

个人Android学习总结


net.hostname 获取接口

<p><strong>简要描述:</strong> </p> <ul> <li>设备id获取接口</li> </ul> <p><strong>数据来源:</strong> </p> <ul> <li>SystemProperties的net.hostname属性值</li> </ul> <p><strong>请求方式:</strong></p> <ul> <li>String hostName = SystemProperties.get(&quot;net.hostname&quot;) ;</li> </ul> <p><strong>参数:</strong> </p> <table> <thead> <tr> <th style="text-align: left;">参数名</th> <th style="text-align: left;">必选</th> <th style="text-align: left;">类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">net.hostname</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>属性key</td> </tr> </tbody> </table> <p><strong>数据格式:</strong> </p> <ul> <li>model-deviceid</li> </ul> <table> <thead> <tr> <th style="text-align: left;">参数名</th> <th style="text-align: left;">必选</th> <th style="text-align: left;">类型</th> <th>说明</th> <th>默认值</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">model</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>ro.product.model字段的属性值</td> </tr> <tr> <td style="text-align: left;">deviceid</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>出厂前录入的设备号id,位数不固定</td> <td>00000000</td> </tr> </tbody> </table> <p><strong>返回示例</strong></p> <ul> <li> <p>例如:QD400-sn1234567890</p> <p><strong>备注</strong> </p> </li> <li>当录入设备号id失败或者未录入设备号,返回的hostName值, 例如:QD400-00000000</li> <li>如果android.os.SystemProperties.get() 读取系统属性的方法是系统隐藏,无法直接使用,可以使用Java反射。</li> </ul> <pre><code class="language-java">static Method systemProperties_get = null; static String getAndroidOsSystemProperties(String key) { String ret; try { systemProperties_get = Class.forName(&amp;quot;android.os.SystemProperties&amp;quot;).getMethod(&amp;quot;get&amp;quot;, String.class); if ((ret = (String) systemProperties_get.invoke(null, key)) != null) return ret; } catch (Exception e) { e.printStackTrace(); return null; } return &amp;quot;&amp;quot;; } </code></pre> <pre><code class="language-java"> static Method systemProperties_set = null; public static void setAndroidOsSystemProperties(String key,String value){ try { Class&amp;lt;?&amp;gt; systemProperties = Class.forName(&amp;quot;android.os.SystemProperties&amp;quot;); systemProperties_set = systemProperties.getMethod(&amp;quot;set&amp;quot;, String.class, String.class); systemProperties_set.invoke(systemProperties, key,value); Log.d(&amp;quot;sntest&amp;quot;, &amp;quot;systemProperties_set.invoke&amp;quot;); } catch (Exception e) { e.printStackTrace(); Log.d(&amp;quot;sntest&amp;quot;, &amp;quot;setAndroidOsSystemProperties --&amp;gt;e : &amp;quot;+e.getMessage()); } }</code></pre> <p>注释: 通过反射, 只有访问SystemProperties的get方法权限,没有访问set方法的权限,设置后无效,值不会改变,谨防属性被恶意篡改。</p>

页面列表

ITEM_HTML