我的应用程序中有一个自动错误报告工具,其中包含有用的调试信息.
我想要包括的一件事是ROM提供商.特别是我想知道用户是否正在运行自定义ROM,最好是使用版本号.
知道如何以编程方式检索此信息吗?
---取自Quintin(见下文)
public static String getReadableModVersion() {
String modVer = getSystemProperty(Constants.SYS_PROP_MOD_VERSION);
return (modVer == null || modVer.length() == 0 ? "Unknown" : modVer);
}
Run Code Online (Sandbox Code Playgroud)
这个常数是这样的:
public static final String SYS_PROP_MOD_VERSION = "ro.modversion";
Run Code Online (Sandbox Code Playgroud)
这是getSystemProperty();
public static String getSystemProperty(String propName){
String line;
BufferedReader input = null;
try
{
Process p = Runtime.getRuntime().exec("getprop " + propName);
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
line = input.readLine();
input.close();
}
catch (IOException ex)
{
Log.e(TAG, "Unable to read sysprop " + propName, ex);
return null;
}
finally
{
if(input != null)
{
try
{
input.close();
}
catch (IOException e)
{
Log.e(TAG, "Exception while closing InputStream", e);
}
}
}
return line;
}
Run Code Online (Sandbox Code Playgroud)
任何拥有CM ROM的人都可以为我运行吗?
顺便说一句.小心,这是GPL代码.我一个人不能用它.任何更简单或非GPL的方式?
我不知道是否有明确的提供者指标,但你可以检查内容/proc/version.这是CyanogenMod 4.0.4的输出:
Linux版本2.6.29.6-cm4(阴影@ toxygen)(gcc版本4.4.0(GCC))#8 PREEMPT 8月28日星期五20:30:25 EDT 2009
这里的提示是"cm4"后缀,(我相信)代表CyanogenMod 4(加上独特的用户@ host位,尽管不太清楚).为了比较,这是运行1.6的模拟器的版本:
Linux版本2.6.27-00110-g132305e(mikechan@cheetara.corp.google.com)(gcc版本4.2.1)#6星期一2月2日12:47:38 PST 2009
您还可以检查值android.os.Build.没有太多信息Build.TYPE,但我假设类型"eng"代表官方构建,类型"user"代表自制构建,所以这也可能有用.
Cyanogen-Updater项目中有具有此功能的代码,尽管我认为 rom 信息是由 rom 开发人员提供的 prop 文件提供的,所以我不确定它是否可以普遍使用。我还没有彻底研究过这个问题,但你可以看看来源并弄清楚。
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |