Android PackageInfo - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android PackageInfo class.

This code example shows how to use the following methods:
    assertThat(info.packageName).isEqualTo(Robolectric.application.getPackageName());
  } 
 
  @Test 
  public void getApplicationInfo__OtherApplication() throws Exception { 
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = TEST_PACKAGE_NAME;
    packageInfo.applicationInfo = new ApplicationInfo();
    packageInfo.applicationInfo.packageName = TEST_PACKAGE_NAME;
    packageInfo.applicationInfo.name = TEST_PACKAGE_LABEL;
    rpm.addPackage(packageInfo);
 
    ApplicationInfo info = rpm.getApplicationInfo(TEST_PACKAGE_NAME, 0);
    assertThat(info).isNotNull();
    assertThat(info.packageName).isEqualTo(TEST_PACKAGE_NAME);
    assertThat(rpm.getApplicationLabel(info).toString()).isEqualTo(TEST_PACKAGE_LABEL);
  } 
 
  @Test(expected = PackageManager.NameNotFoundException.class) 
  public void removePackage_shouldHideItFromGetApplicationInfo() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:
        assertThat(info.packageName).isEqualTo(Robolectric.application.getPackageName());
    } 
 
    @Test 
    public void getApplicationInfo__OtherApplication() throws Exception { 
        PackageInfo packageInfo = new PackageInfo();
        packageInfo.packageName = TEST_PACKAGE_NAME;
        packageInfo.applicationInfo = new ApplicationInfo();
        packageInfo.applicationInfo.packageName = TEST_PACKAGE_NAME;
        packageInfo.applicationInfo.name = TEST_PACKAGE_LABEL;
        rpm.addPackage(packageInfo);
 
        ApplicationInfo info = rpm.getApplicationInfo(TEST_PACKAGE_NAME, 0);
        assertThat(info).isNotNull();
        assertThat(info.packageName).isEqualTo(TEST_PACKAGE_NAME);
        assertThat(rpm.getApplicationLabel(info).toString()).isEqualTo(TEST_PACKAGE_LABEL);
    } 
 
    @Test(expected = PackageManager.NameNotFoundException.class) 
    public void removePackage_shouldHideItFromGetApplicationInfo() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:
     * already 'installed' on system. 
     *  
     * @param packageInfo 
     */ 
    public void addPackage( PackageInfo packageInfo ) {
    	 packageList.put(packageInfo.packageName, packageInfo);
    } 
     
    public void addPackage( String packageName ) {
    	PackageInfo info = new PackageInfo();
    	info.packageName = packageName;
    	addPackage( info );
    }     
     
    private void initializePackageInfo() { 
    	if (packageList != null) { return; }
 
        PackageInfo packageInfo = new PackageInfo();
        packageInfo.packageName = contextWrapper.getPackageName();
        packageInfo.versionName = "1.0";

6
CodeRank
This code example shows how to use the following methods:
 
        @Override 
        public PackageInfo getPackageInfo(String packageName, int flags)
                throws NameNotFoundException { 
 
            PackageInfo info = new PackageInfo();
            info.signatures = new Signature[] {
                new Signature(testSignature)
            }; 
            return info;
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
        try { 
            packageInfo = mPackageManager.getPackageInfo(packageName,
                    PackageManager.GET_PROVIDERS | PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            // The package got removed 
            packageInfo = new PackageInfo();
            packageInfo.packageName = packageName;
        } 
 
        updateDirectoriesForPackage(packageInfo, false);
    } 
 
 
    /** 
     * Scans the specified package for content directories and updates the {@link Directory} 
     * table accordingly. 
     */ 
    private List<DirectoryInfo> updateDirectoriesForPackage(
            PackageInfo packageInfo, boolean initialScan) {
        ArrayList<DirectoryInfo> directories = Lists.newArrayList();
5
CodeRank
This code example shows how to use the following methods:
		PackageInfo pi;
		try { 
			pi = pm.getPackageInfo(mAct.getPackageName(), 0);
		} catch (NameNotFoundException nnfe) {
			//doubt this will ever run since we want info about our own package 
			pi = new PackageInfo();
			pi.versionName = "unknown";
			pi.versionCode = 69;
		} 
		Date theDate = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz");
		String s = "-------- Environment --------\n";
		s += "Time\t= "+sdf.format(theDate)+"\n";
		s += "Device\t= "+Build.FINGERPRINT+"\n";
		try { 
			Field theMfrField = Build.class.getField("MANUFACTURER");
			s += "Make\t="+theMfrField.get(null)+"\n";
		} catch (SecurityException e) {
		} catch (NoSuchFieldException e) {
		} catch (IllegalArgumentException e) {
3
CodeRank
This code example shows how to use the following methods:
 
	private ArrayList<PackageInfo> getSkinPackages() {
		 
		mSkinIndex = 0;
		mSkinPackages = new ArrayList<PackageInfo>();
		mSkinPackages.add(new PackageInfo());		
		 
//		List<PackageInfo> packs = pm.getInstalledSkinPackages();		 
//		for(int i = 0;i < packs.size();i++){ 
//			PackageInfo pi = packs.get(i);					 
//			if(pi.applicationInfo.skinType.equals("skin")){ 
//				Log.w(TAG, "Adding package " +pi.packageName); 
//				mSkinPackages.add(pi); 
//			} 
//			if(pi.packageName.equals(getResources().getConfiguration().skin)){ 
//				mSkinIndex = i+1; 
//			} 
//		}	 
		return mSkinPackages;
	} 
4
CodeRank
This code example shows how to use the following methods:
		PackageManager pm = ctx.getPackageManager();
		PackageInfo packageInfo = null;
		try { 
			packageInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
		} catch (NameNotFoundException e) {
			packageInfo = new PackageInfo();
			packageInfo.packageName = "";
		} 
		return packageInfo;
	} 
 
	public List<CarPark> readCarParksFromFile() {
		String data = readRawResource(R.raw.car_park_rates);
		return stringToCarPars(data);
	} 
 
	private List<CarPark> stringToCarPars(String data) {
		String[] iProperties = data.split("<m:properties>");
		List<CarPark> carParks = new ArrayList<CarPark>();
		for (String str : iProperties) {
4
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:

Related Android PackageInfo Questions & Answers:

See Code Examples for Android PackageInfo Methods: