Search in sources :

Example 36 with PackageInfo

use of android.content.pm.PackageInfo in project Etar-Calendar by Etar-Group.

the class AboutPreferences method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.about_preferences);
    final Activity activity = getActivity();
    try {
        final PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        findPreference(BUILD_VERSION).setSummary(packageInfo.versionName);
    } catch (NameNotFoundException e) {
        findPreference(BUILD_VERSION).setSummary("?");
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Activity(android.app.Activity)

Example 37 with PackageInfo

use of android.content.pm.PackageInfo in project SeeWeather by xcc3641.

the class Util method getVersionCode.

/**
     * @return 版本号
     */
public static int getVersionCode(Context context) {
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) IOException(java.io.IOException)

Example 38 with PackageInfo

use of android.content.pm.PackageInfo in project CloudReader by youlookwhat.

the class BaseTools method getVersionName.

/**
     * 获取当前应用的版本号
     */
public static String getVersionName() {
    // 获取packagemanager的实例
    PackageManager packageManager = CloudReaderApplication.getInstance().getPackageManager();
    // getPackageName()是你当前类的包名,0代表是获取版本信息
    PackageInfo packInfo = null;
    try {
        packInfo = packageManager.getPackageInfo(CloudReaderApplication.getInstance().getPackageName(), 0);
        return packInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "1.0";
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 39 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.

the class WallpaperBackupAgent method servicePackageExists.

private boolean servicePackageExists(ComponentName comp) {
    try {
        if (comp != null) {
            final IPackageManager pm = AppGlobals.getPackageManager();
            final PackageInfo info = pm.getPackageInfo(comp.getPackageName(), 0, UserHandle.USER_SYSTEM);
            return (info != null);
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "Unable to contact package manager");
    }
    return false;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 40 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.

the class BackupManagerService method requestBackup.

public int requestBackup(String[] packages, IBackupObserver observer) {
    mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "requestBackup");
    if (packages == null || packages.length < 1) {
        Slog.e(TAG, "No packages named for backup request");
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        throw new IllegalArgumentException("No packages are provided for backup");
    }
    IBackupTransport transport = getTransport(mCurrentTransport);
    if (transport == null) {
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        return BackupManager.ERROR_TRANSPORT_ABORTED;
    }
    ArrayList<String> fullBackupList = new ArrayList<>();
    ArrayList<String> kvBackupList = new ArrayList<>();
    for (String packageName : packages) {
        try {
            PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (!appIsEligibleForBackup(packageInfo.applicationInfo)) {
                sendBackupOnPackageResult(observer, packageName, BackupManager.ERROR_BACKUP_NOT_ALLOWED);
                continue;
            }
            if (appGetsFullBackup(packageInfo)) {
                fullBackupList.add(packageInfo.packageName);
            } else {
                kvBackupList.add(packageInfo.packageName);
            }
        } catch (NameNotFoundException e) {
            sendBackupOnPackageResult(observer, packageName, BackupManager.ERROR_PACKAGE_NOT_FOUND);
        }
    }
    EventLog.writeEvent(EventLogTags.BACKUP_REQUESTED, packages.length, kvBackupList.size(), fullBackupList.size());
    if (MORE_DEBUG) {
        Slog.i(TAG, "Backup requested for " + packages.length + " packages, of them: " + fullBackupList.size() + " full backups, " + kvBackupList.size() + " k/v backups");
    }
    String dirName;
    try {
        dirName = transport.transportDirName();
    } catch (Exception e) {
        Slog.e(TAG, "Transport unavailable while attempting backup: " + e.getMessage());
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        return BackupManager.ERROR_TRANSPORT_ABORTED;
    }
    Message msg = mBackupHandler.obtainMessage(MSG_REQUEST_BACKUP);
    msg.obj = new BackupParams(transport, dirName, kvBackupList, fullBackupList, observer, true);
    mBackupHandler.sendMessage(msg);
    return BackupManager.SUCCESS;
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) Message(android.os.Message) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1566 PackageManager (android.content.pm.PackageManager)702 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)327 ApplicationInfo (android.content.pm.ApplicationInfo)217 Test (org.junit.Test)193 RemoteException (android.os.RemoteException)179 ArrayList (java.util.ArrayList)166 Intent (android.content.Intent)126 IOException (java.io.IOException)121 Context (android.content.Context)81 IPackageManager (android.content.pm.IPackageManager)65 ResolveInfo (android.content.pm.ResolveInfo)65 File (java.io.File)62 SuppressLint (android.annotation.SuppressLint)58 ComponentName (android.content.ComponentName)57 ActivityInfo (android.content.pm.ActivityInfo)57 View (android.view.View)57 TextView (android.widget.TextView)54 Signature (android.content.pm.Signature)51 OverlayInfo (android.content.om.OverlayInfo)42