开发者

android indexof an arraylist returned by getInstalledPackages

What is the object parameter in indexOf() when used with the List returned by getPackageManager().getInstalledPackages(0)? I have done a Collections.sort on the list with a comparator comparing packageName. I want to get the indexOf based on a string that is a packageName but I cant figure out how that parameter will be formed. I've tried

PackageInfo searchInfo = new PackageInfo();
        searchInfo.packageName = p开发者_Go百科rocName;
        int nameIndex = packs.indexOf(searchInfo); 

and it returns -1


You may look at this code.Here you can compare with packageName.....

List<ApplicationInfo> packages;
    PackageManager pm;
    pm = getPackageManager();
             get a list of installed apps.
            packages = pm.getInstalledApplications(0);

ActivityManager mActivityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);

   for (ApplicationInfo packageInfo : packages) {
    if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
    if(packageInfo.packageName.equals("mypackage")) continue;



                      }


check this line: int nameIndex = packs.indexOf(searchInfo); and observe searchInfo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜