Android在设置里面显示新属性的方法

1./usr/smdt/self6000/android/packages/apps/Settings/res/xml/device_info_settings.xml

中增加节点:

<!-- Detailed build version-->

<Preference
android:key="build_number"

style="?android:preferenceInformationStyle"

android:title="@string/build_number"

android:summary="@string/device_info_default"/>

<!-- Device test -->

<Preference android:key="device_test"

style="?android:preferenceInformationStyle"

android:title="@string/device_test"

android:summary="@string/device_func_test"/>

<!-- Laohua test -->

<Preference android:key="laohua_test"

style="?android:preferenceInformationStyle"

android:title="@string/laohua_test"

android:summary="@string/laohua_func_test"/>

<!—Device NO -->

<Preference android:key="device_no"

style="?android:preferenceInformationStyle"

android:title="@string/device_no"

android:summary="@string/device_esn_no"/>

2. /usr/smdt/self6000/android/packages/apps/Settings/res/values/strings.xml

增加

<string
name="kernel_version">Kernel version</string>

<!-- About phone screen,  setting option name-->

<string
name="build_number">Build number</string>

<string name="device_test">"functiontest"</string>

<stringname="device_func_test">"functiontest"</string>

<stringname="laohua_test">"old test"</string>

<stringname="laohua_func_test">"old test"</string>

<string name="device_no">"devicenumber"</string>

<string name="device_esn_no">"device esn no"</string>

3./usr/smdt/self6000/android/packages/apps/Settings/res/values-zh-rCN/strings.xml

增加:

<string
name="kernel_version"msgid="9192574954196167602">"内核版本"</string>

<string
name="build_number"
msgid="3075795840572241758">"版本号"</string>

<stringname="device_test">"功能测试"</string>

<string name="device_func_test">"设备功能测试"</string>

<string name="laohua_test">"老化测试"</string>

<string name="laohua_func_test">"老化测试"</string>

<string name="device_no">"设备编号"</string>

<string name="device_esn_no">"设备编号"</string>

4./usr/smdt/self6000/android/packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java

修改:

   private
staticfinal
String
KEY_EQUIPMENT_ID =
"fcc_equipment_id";

privatestaticfinalString
PROPERTY_EQUIPMENT_ID =
"ro.ril.fccid";

privatestatic final String
KEY_DEVICE_TEST ="device_test";

   private
static final String KEY_LAOHUA_TEST = "laohua_test";

   private
static final String KEY_DEVICE_NO = "device_no";

static
final int
TAPS_TO_BE_A_DEVELOPER
= 7;

onCreate方法增加:

setStringSummary(KEY_BUILD_NUMBER,Build.DISPLAY);

findPreference(KEY_BUILD_NUMBER).setEnabled(true);

findPreference(KEY_DEVICE_TEST).setEnabled(true);

findPreference(KEY_LAOHUA_TEST).setEnabled(true);

findPreference(KEY_DEVICE_NO).setEnabled(true);

setStringSummary(KEY_DEVICE_NO,getCPUSerial());

findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion());

onPreferenceTreeClick方法:

publicbooleanonPreferenceTreeClick(PreferenceScreen
preferenceScreen, Preference
preference) {

Log.i(LOG_TAG,
"=========="+preference.getKey());

if (preference.getKey().equals(KEY_FIRMWARE_VERSION))
{

System.arraycopy(mHits, 1,
mHits, 0, mHits.length-1);

mHits[mHits.length-1]= SystemClock.uptimeMillis();

if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {

Intent
intent = new Intent(Intent.ACTION_MAIN);

intent.setClassName("android",

com.android.internal.app.PlatLogoActivity.class.getName());

try {

startActivity(intent);

} catch (Exception
e) {

Log.e(LOG_TAG,
"Unable to start activity " +
intent.toString());

}

}

} else
if
(preference.getKey().equals(KEY_BUILD_NUMBER)){

if (mDevHitCountdown > 0) {

mDevHitCountdown--;

if (mDevHitCountdown == 0) {

getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,

Context.MODE_PRIVATE).edit().putBoolean(

DevelopmentSettings.PREF_SHOW,
true).apply();

if (mDevHitToast!=
null){

mDevHitToast.cancel();

}

mDevHitToast = Toast.makeText(getActivity(),R.string.show_dev_on,

Toast.LENGTH_LONG);

mDevHitToast.show();

} else
if
(mDevHitCountdown> 0

&&
mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER-2)){

if (mDevHitToast !=
null){

mDevHitToast.cancel();

}

mDevHitToast = Toast.makeText(getActivity(),getResources().getQuantityString(

R.plurals.show_dev_countdown,mDevHitCountdown,mDevHitCountdown),

Toast.LENGTH_SHORT);

mDevHitToast.show();

}

} else
if
(mDevHitCountdown< 0) {

if (mDevHitToast !=
null){

mDevHitToast.cancel();

}

mDevHitToast = Toast.makeText(getActivity(),R.string.show_dev_already,

Toast.LENGTH_LONG);

mDevHitToast.show();

}

}else
if(preference.getKey().equals(KEY_DEVICE_TEST)){

doStartApplicationWithPackageName("com.smdt.test.basic");

}else
if(preference.getKey().equals(KEY_LAOHUA_TEST)){

doStartApplicationWithPackageName("com.into.stability");}

return
super
.onPreferenceTreeClick(preferenceScreen,
preference);

}

 

增加doStartApplicationWithPackageName方法:

private
void
doStartApplicationWithPackageName(String
packagename) {

//
通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等

PackageInfo
packageinfo = null;

try {

packageinfo =getPackageManager().getPackageInfo(packagename, 0);

} catch (NameNotFoundException
e) {

e.printStackTrace();

}

if (packageinfo ==
null){

return;

}

//
创建一个类别为CATEGORY_LAUNCHER的该包名的Intent

Intent
resolveIntent = new Intent(Intent.ACTION_MAIN,
null);

resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

resolveIntent.setPackage(packageinfo.packageName);

//
通过getPackageManager()的queryIntentActivities方法遍历

List<ResolveInfo>
resolveinfoList =getPackageManager()

.queryIntentActivities(resolveIntent, 0);

ResolveInfo
resolveinfo = resolveinfoList.iterator().next();

if (resolveinfo !=
null){

// packagename = 参数packname

String
packageName = resolveinfo.activityInfo.packageName;

// 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname]

String
className = resolveinfo.activityInfo.name;

// LAUNCHER Intent

Intent
intent = new Intent(Intent.ACTION_MAIN);

intent.addCategory(Intent.CATEGORY_LAUNCHER);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// 设置ComponentName参数1:packagename参数2:MainActivity路径

ComponentName
cn = new ComponentName(packageName,
className);

intent.setComponent(cn);

startActivity(intent);

}

}

增加获取cpu序列号的方法:

 

/**

*
获取CPU序列号

*

*
@return
CPU序列号(16位)

*
读取失败为"0000000000000000"

*/

publicstaticString getCPUSerial() {

String
str= "",strCPU =
"",
cpuAddress =
"0000000000000000";

try{

//读取CPU信息

Process
pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");

InputStreamReader
ir = new InputStreamReader(pp.getInputStream());

LineNumberReader
input = new LineNumberReader(ir);

//查找CPU序列号

for (int
i = 1; i < 100;
i++) {

str =
input.readLine();

if (str !=
null){

//查找到序列号所在行

if (str.indexOf("Serial")> -1) {

//提取序列号

strCPU =
str.substring(str.indexOf(":") + 1,

str.length());

//去空格

cpuAddress =
strCPU.trim();

break;

}

}else{

//文件结尾

break;

}

}

} catch(IOException
ex) {

//赋予默认值

ex.printStackTrace();

}

returncpuAddress;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-03 06:43:13

Android在设置里面显示新属性的方法的相关文章

Android中设置文本颜色的三种方法及颜色大全

原文:Android中设置文本颜色的三种方法及颜色大全 源代码下载地址:http://www.zuidaima.com/share/1550463694572544.htm 1.利于系统自带的颜色类 如TextView1.setTextColor(Android.graphics.Color.RED); 2.数字颜色表示法 TextView1.setTextColor(0xffff00ff); 3.自定义颜色 TextView1.setTextColor(this.getResources().

FlashBuilder 4.6 Bug 代码提示无法显示 变量属性和方法

用FlashBuilder4.6 创建Flex 项目,如果在Application中用 fx:Metadata 添加元数据,然后又注释掉(使用单行//或多行/* */注释),FlashBuilder4.6的代码提示就会出现异常,无法再显示变量的属性.方法,无法按Ctrl+1自动添加函数体.事件处理函数.仅能再显示 类.包的提示. 所以不要再FlashBuilder4.6 的Flex项目中写如下代码 <fx:Metadata> // ---- </fx:Metadata> 或是 &l

vue 添加对象的新属性的方法

和数组一样,Vue 不能检测到对象属性的添加或删除.由于 Vue 会在初始化实例时对属性执行 getter/setter 转化过程,所以属性必须在 data 对象上存在才能让 Vue 转换它,这样才能让它是响应的. 两种不同情况下使用的方法: Vue.set(object, key, value) Vue.set(vm.someObject, 'b', 2) vm.$set this.$set(this.someObject,'b',2) 如果想向已有对象上添加一些属性,例如使用 Object.

Android中设置文本颜色的三种方法

1.利于系统自带的颜色类 如TextView1.setTextColor(android.graphics.Color.RED); //2014.12.9 布局文件中:android:textColor="@android:color/white" 详见Android源码base/core/res/res/values/colors.xml 2.数字颜色表示法 TextView1.setTextColor(0xffff00ff); 3.自定义颜色 TextView1.setTextCo

Android中TextView和EditView常用属性设置

Android开发中最常用的差不多就是TextView和EditView了,在使用它时,我们也会设置它的一些属性,为了让我们设计的更好看,设置的更合理.这里记下它的常用属性,方便后期查阅. EditText属性描述 android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom android:background="@android:drawable/edit_text"这个属性,

Android控件Editext、TextView属性详解

EditText属性描述 android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom android:hint="请输入数字!"//设置显示在空间上的提示信息 android:numeric="integer"//设置只能输入整数,如果是小数则是:decimal android:singleLine="true"//设置单行输入,一旦设置为

Android 编辑框(EditText)属性学习

EditText的属性很多,这里介绍几个:android:hint="请输入数字!"//设置显示在空间上的提示信息android:numeric="integer"//设置只能输入整数,如果是小数则是:decimalandroid:singleLine="true"//设置单行输入,一旦设置为true,则文字不会自动换行.android:password="true"//设置只能输入密码android:textColor =

Android EditText多行显示及所有属性

android:id="@+id/editSms" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/saveSms" android:inputType="textMultiLine" android:gravity="left|top" andro

android颜色设置

Android中的颜色设置 1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 1 2 3 public static final class color {     public static final int lightblue=0x7f040000; } 或者在Java中tx.setTextColor(0xffff00f); 说明: 0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x表示颜色整数的标记,ff表示透明度,f00f表示色值,注