我为具有属性“android:description”的活动定义了描述如何以编程方式获取它?
我试过这段代码:
PackageManager pm = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.addCategory(CATEGORY);
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
String desc = "";
try {
desc = res.getString(info.activityInfo.descriptionRes);
} catch(NotFoundException e) {
desc = info.activityInfo.name;
}
}
此代码引发 NotFoundException。
我在调试模式下观察了这个值,参数“descriptionRes”确实有一个 int 值。
如何获得描述?非常感谢,如果有任何帮助。