tags:

views:

139

answers:

3

Hi,

I have this piece of code that I would like to shorten...

    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);

I am seriously irritated to do this again and again to add new flag permissions, and I need to do it a couple of times, is there a shorter method in which I could put all the flags on the same definition...???

Let me put it this way, can I do this...??? (of course this gives an error, but something similar..)

    PackageManager p = context.getPackageManager();
    final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS).addFlag(PackageManager.GET_PROVIDERS);
A: 

Im not sure if I understand you correctly, but why are you doing this? Do you want to add permissions to your activity? Then you can do this in your manifest file.

Roflcoptr
No I trying to retrieve the permissions from the packages installed. Apart from permission I also intend to retrieve content providers, services, etc etc.. Each time I need to set the flag for the package, so I was wondering if there was a way to assign multiple flags on the same declaration...
Shouvik
A: 

check the android Documentation: for permissions: http://developer.android.com/guide/topics/manifest/uses-permission-element.html

for providers: http://developer.android.com/guide/topics/manifest/provider-element.html

Before that Completely study about manifest documentation

Praveen Chandrasekaran
edited the question, please take a look and see if its more clear... thanks...
Shouvik
+2  A: 

If it's the same syntax as C# and the flags are set properly, you could do this:

PackageManager p = context.getPackageManager(); 
final List<PackageInfo> appinstall = 
    p.getInstalledPackages(PackageManager.GET_PERMISSIONS | 
                                      PackageManager.GET_PROVIDERS)
ck
Brilliant, this is exactly what I needed! =)Thanks a Ton!
Shouvik