Java: Need some way to shorten this code

前端 未结 3 1095
广开言路
广开言路 2020-11-30 09:17

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

    PackageManager p = context.getPackageManager();
    final List appinstall =          


        
相关标签:
3条回答
  • 2020-11-30 09:43

    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)
    
    0 讨论(0)
  • 2020-11-30 09:59
    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());
    
        }
    
    }
    
    0 讨论(0)
  • 2020-11-30 10:06

    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

    0 讨论(0)
提交回复
热议问题