List of usage examples for android.content Context getApplicationInfo
public abstract ApplicationInfo getApplicationInfo();
From source file:com.aps490.drdc.prototype.MainActivity.java
public static void initNativeLib(Context context) { try {/* w w w . j av a2 s . c o m*/ // Try loading our native lib, see if it works... System.loadLibrary("libarchitect"); } catch (UnsatisfiedLinkError er) { ApplicationInfo appInfo = context.getApplicationInfo(); String libName = "libarchitect.so"; String destPath = context.getFilesDir().toString(); try { String soName = destPath + File.separator + libName; new File(soName).delete(); UnzipUtil.extractFile(appInfo.sourceDir, "lib/" + Build.CPU_ABI + "/" + libName, destPath); System.load(soName); } catch (IOException e) { // extractFile to app files dir did not work. Not enough space? Try elsewhere... destPath = context.getExternalCacheDir().toString(); // Note: location on external memory is not secure, everyone can read/write it... // However we extract from a "secure" place (our apk) and instantly load it, // on each start of the app, this should make it safer. String soName = destPath + File.separator + libName; new File(soName).delete(); // this copy could be old, or altered by an attack try { UnzipUtil.extractFile(appInfo.sourceDir, "lib/" + Build.CPU_ABI + "/" + libName, destPath); System.load(soName); } catch (IOException e2) { Log.e("AMMAR:", "Exception in InstallInfo.init(): " + e); e.printStackTrace(); } } } }
From source file:com.amazonaws.mobileconnectors.util.ClientContext.java
/** * Gets the client info, including installation_id_id, app_title, * app_version_name, app_version_code, and app_package_name. * * @param context context of the app//from w ww .j av a2 s. c o m * @return an JSONObject that has the client info * @throws JSONException */ static JSONObject getClientInfo(Context context) throws JSONException { final JSONObject client = new JSONObject(); final PackageManager packageManager = context.getPackageManager(); try { final PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); final ApplicationInfo applicationInfo = context.getApplicationInfo(); client.put("installation_id", getInstallationId(context)) .put("app_version_name", packageInfo.versionName) .put("app_version_code", String.valueOf(packageInfo.versionCode)) .put("app_package_name", packageInfo.packageName); // If null is returned for some reason, fall back to "Unknown" final CharSequence title = packageManager.getApplicationLabel(applicationInfo); client.put("app_title", title == null ? "Unknown" : title.toString()); } catch (final NameNotFoundException e) { // When device starts, PackageManager will gather package // information by scanning them. It will take a while to finish. // This exception may be thrown when scan doesn't finish. LOGGER.warn("Failed to load package info: " + context.getPackageName(), e); } return client; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ????<br/>/*from w w w . jav a 2 s . c om*/ * ?id??????+?? * * @param context * @return */ public static String getCurProcessName(Context context) { final int curPid = android.os.Process.myPid(); String curProcessName = getProcessNameByPid(context, curPid); if (null == curProcessName) { curProcessName = context.getApplicationInfo().processName; LogUtil.d(TAG, "getCurProcessName,no find process,curPid=", curPid, ",curProcessName=", curProcessName); } return curProcessName; }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
private static String m119u(Context context) { Object obj = context.getApplicationInfo().name; if (!TextUtils.isEmpty(obj)) { return obj; }//ww w .j a v a2 s.com ApplicationInfo applicationInfo; String packageName = context.getPackageName(); PackageManager packageManager = context.getApplicationContext().getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { applicationInfo = null; } return applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName; }
From source file:uk.ac.horizon.ug.exploding.client.logging.LoggingUtils.java
/** * @param context//w w w . j a va2s .c o m */ private static void logHeader(Context context) { TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = mTelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE try { JSONStringer js = new JSONStringer(); js.object(); js.key("imei"); js.value(imei); js.key("time"); js.value(System.currentTimeMillis()); js.key("package"); js.value(context.getApplicationInfo().packageName); js.key("application"); js.value(context.getApplicationInfo().name); js.key("os.name"); js.value(System.getProperty("os.name")); js.key("os.arch"); js.value(System.getProperty("os.arch")); js.key("os.version"); js.value(System.getProperty("os.version")); PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); js.key("versionName"); js.value(pi.versionName); js.key("versionCode"); js.value(pi.versionCode); } catch (NameNotFoundException e) { Log.e(TAG, "Checking package info", e); } js.key("phoneModel"); js.value(android.os.Build.MODEL); js.key("androidVersion"); js.value(android.os.Build.VERSION.RELEASE); js.endObject(); log(LOGTYPE_HEADER, js.toString()); } catch (Exception e) { Log.e(TAG, "Creating log data (header)", e); } }
From source file:se.dw.okhttpwrapper.ImageRequest.java
public static ImageRequest initiateWDiskCache(Context context, int inMaxImageWidth, int inMaxImageHeight, int cacheSize) { maxImageWidth = inMaxImageWidth;/*from ww w.ja va 2 s . co m*/ maxImageHeight = inMaxImageHeight; cacheSize = cacheSize * 1024 * 1024; String uniqueName = context.getApplicationInfo().packageName; fileCache = new DiskLruImageCache(context, uniqueName, cacheSize, CompressFormat.PNG, 100); imageDownloader = null; return getInstance(); }
From source file:com.readystatesoftware.notificationlog.Log.java
private static boolean isActivityAvailable(Context context, String className) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(); final String packageName = context.getApplicationInfo().packageName; intent.setClassName(packageName, className); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:com.readystatesoftware.notificationlog.Log.java
/** * Initialize the NotificationLog so that subsequent calls to the various * Log methods will send output to a notification in addition to the system * log. If you do not call this method, this class behaves exactly as * android.util.Log./*from w ww. j ava2s . com*/ * * @param context your application context * @param icon drawable resource identifier to use as the notification icon */ public static void initialize(Context context, int icon) { sLog.mContext = context; sLog.mLogToast0 = new Toast(context); sLog.mLogToast1 = new Toast(context); sLog.mIcon = (icon == 0) ? context.getApplicationInfo().icon : icon; sLog.mLabel = context.getString(context.getApplicationInfo().labelRes); sLog.mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); sLog.mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); sLog.mLevel = sLog.mPrefs.getInt(PREF_LEVEL, VERBOSE); sLog.mFilter = sLog.mPrefs.getString(PREF_FILTER, null); Intent intent = new Intent(context, LogActivity.class); sLog.mViewIntent = PendingIntent.getActivity(context, 0, intent, 0); Intent filterIntent = new Intent(context, LogActivity.class); filterIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_FILTER); sLog.mFilterIntent = PendingIntent.getActivity(context, 4, filterIntent, 0); Intent levelIntent = new Intent(context, LogActivity.class); levelIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_LEVEL); sLog.mLevelIntent = PendingIntent.getActivity(context, 2, levelIntent, 0); Intent clearIntent = new Intent(context, LogActivity.class); clearIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_CLEAR); sLog.mClearIntent = PendingIntent.getActivity(context, 3, clearIntent, 0); sLog.mActivityIntegrationAvailable = isActivityAvailable(context, LogActivity.class.getName()); }
From source file:it.scoppelletti.mobilepower.app.AppUtils.java
/** * Restituisce il nome del pacchetto di un’applicazione. * /*from ww w . j a va 2 s.c o m*/ * @param ctx Contesto. * @param onlyIfDemo Indica se restituire il nome del pacchetto solo se * l’applicazione è una versione di demo. * @return Nome del pacchetto. Se il parametro {@code onlyIfDemo} * è impostato, può essere {@code null}. */ static String getFullPackageName(Context ctx, boolean onlyIfDemo) { String pkgName, value; Bundle data; ApplicationInfo applInfo; PackageManager pkgMgr; if (ctx == null) { throw new NullPointerException("Argument ctx is null."); } pkgName = ctx.getPackageName(); pkgMgr = ctx.getPackageManager(); try { applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get ApplicationInfo.", ex); applInfo = ctx.getApplicationInfo(); } data = applInfo.metaData; value = (data != null) ? data.getString(AppUtils.METADATA_FULLPACKAGE) : null; if (!StringUtils.isBlank(value)) { pkgName = value; } else if (onlyIfDemo) { return null; } return pkgName; }
From source file:com.pdftron.pdf.utils.Utils.java
public static String encryptIt(Context context, String value) { String cryptoPass = context.getString(context.getApplicationInfo().labelRes); try {// w w w.jav a 2 s .c o m DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(keySpec); byte[] clearText = value.getBytes("UTF8"); // Cipher is not thread safe Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, key); String encrypedValue = Base64.encodeToString(cipher.doFinal(clearText), Base64.DEFAULT); Log.d("MiscUtils", "Encrypted: " + value + " -> " + encrypedValue); return encrypedValue; } catch (Exception e) { Log.d(e.getClass().getName(), e.getMessage()); } return value; }