获得activity方法

最近项目中需要动态获得activity,仔细研究了下,发现这样可以获得:

 

Launcher应用->Workspace.java->updateShortcuts方法->

if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
                            Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {

...................................

}后面,加入如下代码

 

else if(info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT &&
                            Intent.ACTION_MAIN.equals(intent.getAction()) && name != null){
                    	    String[] str=name.flattenToShortString().split("/");
                    	    Log.d("ResolveInfo","str[0]="+str[0]+",str[1]="+str[1]);
                    	    String str1=str[0];
                    	    String str2=str[0]+str[1];
                       	    ComponentName com= new ComponentName(str1,str2);
                            Intent ii=new Intent();
                            ii.setComponent(com);
                            List<ResolveInfo> list=pm.queryIntentActivities(ii, 0);
                            if(list.size()>0){
                            	for(ResolveInfo r:list){
                            		String newtitle=r.loadLabel(pm).toString();
                            		Log.d("ResolveInfo","获得的activity标题="+newtitle);
                            		info.setTitle(newtitle);
                            	}
                            }
                    }
 

你可能感兴趣的:(Activity)