10

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);
Guy
  • 12,250
  • 6
  • 53
  • 70
Shouvik
  • 11,350
  • 16
  • 58
  • 89
  • I am sorry if I am missing something obvious, I can be pretty dumb that way... :P – Shouvik Jul 19 '10 at 11:31
  • Please post what error did you get? – Praveen Jul 19 '10 at 11:52
  • Its solved... Well there was syntax error when I did that, Ck below posted the solution to my question... – Shouvik Jul 19 '10 at 12:00
  • 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. – RoflcoptrException Jul 19 '10 at 11:33
  • 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 Jul 19 '10 at 11:39

3 Answers3

10

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)
cjk
  • 45,739
  • 9
  • 81
  • 112
3
public void usegetPackageInfo(){
    // 
    final ListView lw = (ListView) findViewById(R.id.listView1);

    PackageManager p = lw.getContext().getPackageManager(); 
    final List<PackageInfo> appinstall = 
        p.getInstalledPackages(PackageManager.GET_PERMISSIONS | 
                                          PackageManager.GET_PROVIDERS);
    final TextView tw = (TextView) findViewById(R.id.textView1);
    Iterator it = appinstall.iterator();
    while (it.hasNext()) {
        PackageInfo rf = (PackageInfo) it.next();
        tw.append(rf.toString());

    }

}
Justin
  • 6,611
  • 3
  • 36
  • 57
zhocker
  • 173
  • 1
  • 2
  • 11
0

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
  • 90,477
  • 74
  • 177
  • 219