[Android][工具類]PropertisUtils

package com.cw.testapp.utils;

import android.util.VendorUtils;

import com.cw.testapp.misc.Constants;
import com.gzgd.log.LogUtils;

import java.lang.reflect.Method;

/**

  • Created by lenovo3 on 2016/8/25.
    */
    public class PropertisUtils {
    private final static String TAG = "PropertisUtils";

    public static String getHardware() {
    String result = VendorUtils.Xget(Constants.GET_HWVERSION);
    LogUtils.i(TAG, "HWVERSION:" + result);
    return result;
    }

    public static String getSoftware() {
    String result = VendorUtils.Xget(Constants.GET_SWVERSION);
    LogUtils.i(TAG, "SWVERSION:" + result);
    return result;
    }

    public static String getProductModel() {
    String result = VendorUtils.Xget(Constants.GET_MACHINE_MODEL);
    LogUtils.i(TAG, "MACHINE_MODEL:" + result);
    return result;
    }

    public static String getBuildDate() {
    return getProperities("ro.build.date", "");
    }

    public static String getTestapptwice() {
    return getProperities("testapptwice", "");
    }

    public static void setTestapptwice(String b) {
    setProperties("testapptwice", b);
    }

    public static void setLogOff() {
    setProperties("persist.sys.log.enable", "false");
    }

    public static void setLogOn() {
    setProperties("persist.sys.log.enable", "true");
    }

    public static void setBootAuth() {
    setProperties("service.bootauth.exsit", "0");
    }

    public static String getTemperature() {
    return getProperities("mstar.product.temperature", "");
    }

    public static String getEmmcLife() {
    return getProperities("ro.emmclife", "");
    }

    public static String getEmmcID() {
    return getProperities("ro.emmcid", "");
    }

    public static String getProperities(String key, String defaultValue) {
    String value = "";
    Class<?> systemPropertiesClass;
    Method method = null;
    try {
    systemPropertiesClass = Class.forName("android.os.SystemProperties");
    Class<?> getType[] = new Class[2];
    getType[0] = String.class;
    getType[1] = String.class;
    method = systemPropertiesClass.getMethod("get", getType);
    Object arglist[] = new Object[2];
    arglist[0] = key;
    arglist[1] = defaultValue;
    Object receiver = new Object();
    Object returnValue = method.invoke(receiver, arglist);
    if (receiver != null) {
    value = (String) returnValue;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return value.trim();
    }

public static String setProperties(String key, String value) {
    String Value = null;
    Class<?> SystemPropertiesClass = null;
    Method method = null;

    try {

        SystemPropertiesClass = Class
                .forName("android.os.SystemProperties");
        Class<?> getType[] = new Class[2];
        getType[0] = String.class;
        getType[1] = String.class;
        method = SystemPropertiesClass.getMethod("set", getType);

        Object arglist[] = new Object[2];
        arglist[0] = key;
        arglist[1] = value;

        Object receiver = new Object();

        Object returnvalue = method.invoke(receiver, arglist);
        if (receiver != null) {
            Value = (String) returnvalue;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return Value;
}

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,525評(píng)論 19 139
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom閱讀 3,143評(píng)論 0 3
  • 先創(chuàng)建服務(wù)端的APP 1.官網(wǎng)下載Winrun4j。http://winrun4j.sourceforge.net...
    Alex_1799閱讀 2,082評(píng)論 1 2
  • 轉(zhuǎn)至元數(shù)據(jù)結(jié)尾創(chuàng)建: 董瀟偉,最新修改于: 十二月 23, 2016 轉(zhuǎn)至元數(shù)據(jù)起始第一章:isa和Class一....
    40c0490e5268閱讀 2,032評(píng)論 0 9
  • 通過大致十天左右時(shí)間學(xué)習(xí)方法關(guān)的的學(xué)習(xí),知道了很多的學(xué)習(xí)口才的理論知識(shí)。明白了,持續(xù)行動(dòng)是很重要的。 1....
    大牙蘇_e0dc閱讀 187評(píng)論 1 3

友情鏈接更多精彩內(nèi)容