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("?");
}
}
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;
}
}
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";
}
}
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;
}
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;
}
Aggregations