手动解析apk文件:
String path = Environment.getExternalStorageDirectory() +"/Music/ambience.apk";
File file =new File(path);
PackageManager manager = getPackageManager();
PackageInfo info = manager.getPackageArchiveInfo(path,PackageManager.GET_ACTIVITIES);
Log.e("=====packageName=======" + info.applicationInfo.icon,"=========" + info.applicationInfo.labelRes);
AssetManager assets =null;
try {
assets = AssetManager.class.newInstance();
Method method = AssetManager.class.getMethod("addAssetPath",String.class);
method.invoke(assets,path);
}catch (Exception e) {
Log.e("==packageName===","=======1====" + e);
}
Resources resources =new Resources(assets, getResources().getDisplayMetrics(), getResources().getConfiguration()); textView.setImageDrawable(resources.getDrawable(info.applicationInfo.icon));
Log.e("==packageName===","=======1====" + resources.getString(info.applicationInfo.labelRes));
String clas =null;
for (ActivityInfo ac : info.activities){
if ("LauncherActivity".equals(resources.getString(ac.labelRes))){
clas = ac.name;
break;
}
}
Log.e("==activity===" + clas,"==LauncherActivity==");
Intent intent =new Intent();
intent.setComponent(new ComponentName(info.packageName,clas));
startActivity(intent);
}
网友评论