APP 获取系统ro属性

APP 获取系统ro属性

引用方法:https://my.oschina.net/chaselinfo/blog/213393?p=1

activity_ main.xml :



MainActivity.java :

package com.example.myapplication0411;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import java.lang.reflect.Method;
import android.content.Context;
import android.widget.TextView;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView test = findViewById(R.id.test);
//        String model = SystemProperties.get("ro.product.model");String str0 =   SystemPropertiesProxy.get(this,"ro.build.tags");String str1 =   SystemPropertiesProxy.get(this,"ro.build.description");String str2 =   SystemPropertiesProxy.get(this,"ro.build.fingerprint");test.setText(str0+"\n"+str1+"\n"+str2);}
}class SystemPropertiesProxy {/*** 根据给定Key获取值.** @return 如果不存在该key则返回空字符串* @throws IllegalArgumentException 如果key超过32个字符则抛出该异常*/public static String get(Context context, String key) throws IllegalArgumentException {String ret = "";try {ClassLoader cl = context.getClassLoader();@SuppressWarnings("rawtypes")Class SystemProperties = cl.loadClass("android.os.SystemProperties");//参数类型@SuppressWarnings("rawtypes")Class[] paramTypes = new Class[1];paramTypes[0] = String.class;Method get = SystemProperties.getMethod("get", paramTypes);//参数Object[] params = new Object[1];params[0] = new String(key);ret = (String) get.invoke(SystemProperties, params);} catch (IllegalArgumentException iAE) {throw iAE;} catch (Exception e) {ret = "";//TODO}return ret;}
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部