我有一段我想缩短的代码…
PackageManager p = context.getPackageManager(); final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS); PackageManager pro = context.getPackageManager(); final List<PackageInfo> apllprovides = pro.getInstalledPackages(PackageManager.GET_PROVIDERS);
我一次又一次地添加新的标志权限感到非常恼火,我需要做几次,是否有一个较短的方法可以将所有标志放在同一个定义中?
让我这样说吧,我可以这样做吗?(当然这会产生错误,但是类似。)
PackageManager p = context.getPackageManager(); final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS).addFlag(PackageManager.GET_PROVIDERS);
如果与C#的语法相同,并且标志设置正确,则可以执行以下操作:
PackageManager p = context.getPackageManager(); final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS)