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("net.hostname") ;</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(&quot;android.os.SystemProperties&quot;).getMethod(&quot;get&quot;, String.class);
if ((ret = (String) systemProperties_get.invoke(null, key)) != null)
return ret;
} catch (Exception e) {
e.printStackTrace();
return null;
}
return &quot;&quot;;
} </code></pre>
<pre><code class="language-java"> static Method systemProperties_set = null;
public static void setAndroidOsSystemProperties(String key,String value){
try {
Class&lt;?&gt; systemProperties = Class.forName(&quot;android.os.SystemProperties&quot;);
systemProperties_set = systemProperties.getMethod(&quot;set&quot;, String.class, String.class);
systemProperties_set.invoke(systemProperties, key,value);
Log.d(&quot;sntest&quot;, &quot;systemProperties_set.invoke&quot;);
} catch (Exception e) {
e.printStackTrace();
Log.d(&quot;sntest&quot;, &quot;setAndroidOsSystemProperties --&gt;e : &quot;+e.getMessage());
}
}</code></pre>
<p>注释:
通过反射, 只有访问SystemProperties的get方法权限,没有访问set方法的权限,设置后无效,值不会改变,谨防属性被恶意篡改。</p>