Search in sources :

Example 11 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project XPrivacy by M66B.

the class Util method getSelfVersionName.

public static String getSelfVersionName(Context context) {
    try {
        String self = Util.class.getPackage().getName();
        PackageManager pm = context.getPackageManager();
        PackageInfo pInfo = pm.getPackageInfo(self, 0);
        return pInfo.versionName;
    } catch (NameNotFoundException ex) {
        Util.bug(null, ex);
        return null;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 12 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project XPrivacy by M66B.

the class Util method getSelfVersionCode.

public static int getSelfVersionCode(Context context) {
    try {
        String self = Util.class.getPackage().getName();
        PackageManager pm = context.getPackageManager();
        PackageInfo pInfo = pm.getPackageInfo(self, 0);
        return pInfo.versionCode;
    } catch (NameNotFoundException ex) {
        Util.bug(null, ex);
        return 0;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 13 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project Xposed-Tinted-Status-Bar by MohammadAG.

the class PackageListActivity method loadApps.

@SuppressLint("DefaultLocale")
private void loadApps(ProgressDialog dialog) {
    mAppList.clear();
    PackageManager pm = getPackageManager();
    List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
    dialog.setMax(apps.size());
    int i = 1;
    for (ApplicationInfo appInfo : apps) {
        dialog.setProgress(i++);
        if (appInfo == null)
            continue;
        appInfo.name = appInfo.loadLabel(pm).toString();
        try {
            /* Slower app startup, but fewer apps for the user to go through */
            PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES);
            ActivityInfo[] list = pkgInfo.activities;
            if (list != null)
                mAppList.add(appInfo);
        } catch (NameNotFoundException e) {
            continue;
        }
    }
    ApplicationInfo lockscreenStub = new ApplicationInfo();
    lockscreenStub.name = getString(R.string.android_lockscreen_stub_name);
    lockscreenStub.packageName = PackageNames.LOCKSCREEN_STUB;
    mAppList.add(lockscreenStub);
    Collections.sort(mAppList, new Comparator<ApplicationInfo>() {

        @SuppressLint("DefaultLocale")
        @Override
        public int compare(ApplicationInfo lhs, ApplicationInfo rhs) {
            if (lhs.name == null) {
                return -1;
            } else if (rhs.name == null) {
                return 1;
            } else {
                return lhs.name.toUpperCase().compareTo(rhs.name.toUpperCase());
            }
        }
    });
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 14 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project Inscription by MartinvanZ.

the class ChangeLogDialog method getHTML.

//Returns change log in HTML format 
public String getHTML() {
    //TODO: Remove duplicate code with the method show()
    //Get resources
    final String packageName = mContext.getPackageName();
    final Resources resources;
    try {
        resources = mContext.getPackageManager().getResourcesForApplication(packageName);
    } catch (NameNotFoundException ignored) {
        return "";
    }
    //Create HTML change log
    return getHTMLChangelog(R.xml.changelog, resources, 0);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources)

Example 15 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.

the class BackupManagerService method allAgentPackages.

// Returns the set of all applications that define an android:backupAgent attribute
List<PackageInfo> allAgentPackages() {
    // !!! TODO: cache this and regenerate only when necessary
    int flags = PackageManager.GET_SIGNATURES;
    List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
    int N = packages.size();
    for (int a = N - 1; a >= 0; a--) {
        PackageInfo pkg = packages.get(a);
        try {
            ApplicationInfo app = pkg.applicationInfo;
            if (((app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) || app.backupAgentName == null) {
                packages.remove(a);
            } else {
                // we will need the shared library path, so look that up and store it here
                app = mPackageManager.getApplicationInfo(pkg.packageName, PackageManager.GET_SHARED_LIBRARY_FILES);
                pkg.applicationInfo.sharedLibraryFiles = app.sharedLibraryFiles;
            }
        } catch (NameNotFoundException e) {
            packages.remove(a);
        }
    }
    return packages;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1012 PackageManager (android.content.pm.PackageManager)358 PackageInfo (android.content.pm.PackageInfo)291 ApplicationInfo (android.content.pm.ApplicationInfo)235 Intent (android.content.Intent)143 ComponentName (android.content.ComponentName)134 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)105 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)91 UserHandle (android.os.UserHandle)79 ResolveInfo (android.content.pm.ResolveInfo)72 ArrayList (java.util.ArrayList)68 RemoteException (android.os.RemoteException)63 File (java.io.File)57 TextView (android.widget.TextView)52 View (android.view.View)47 FileNotFoundException (java.io.FileNotFoundException)44