最近需要一个功能,从一个apk文件中读取该程序的包名和主activity(入口)的全名
希望大家提供一下思路,java语言最好,android程序也可以
因为有一个较大的工作量,所以如果写成手机程序了不是太方便,所以最好是java的
------解决方案--------------------
自己体会吧:
protected List<PickAdapter.Item> getItems() {
PackageManager packageManager = getPackageManager();
List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>();
// Add any injected pick items
final Intent intent = getIntent();
ArrayList<String> labels =
intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME);
ArrayList<ShortcutIconResource> icons =
intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (labels != null && icons != null && labels.size() == icons.size()) {
for (int i = 0; i < labels.size(); i++) {
String label = labels.get(i);
Drawable icon = null;
try {
// Try loading icon from requested package
ShortcutIconResource iconResource = icons.get(i);
Resources res = packageManager.getResourcesForApplication(
iconResource.packageName);
icon = res.getDrawable(res.getIdentifier(
iconResource.resourceName, null, null));
} catch (NameNotFoundException e) {
// Ignore
}
items.add(new PickAdapter.Item(this, label, icon));
}
}
// Add any intent items if base was given
if (mBaseIntent != null) {
putIntentItems(mBaseIntent, items);
}
return items;
}