public static String logKeyHash(Activity context) { PackageInfo packageInfo; String key = null; try { // getting application package name, as defined in manifest String packageName = context.getApplicationContext().getPackageName(); // Retriving package info packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); Log.e("Package Name=", context.getApplicationContext().getPackageName()); for (Signature signature : packageInfo.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); key = new String(Base64.encode(md.digest(), 0)); // String key = new String(Base64.encodeBytes(md.digest())); Log.e("Key Hash=", key); } } catch (NameNotFoundException e1) { Log.e("Name not found", e1.toString()); } catch (NoSuchAlgorithmException e) { Log.e("No such an algorithm", e.toString()); } catch (Exception e) { Log.e("Exception", e.toString()); } return key; }
/** * [获取应用程序版本名称信息]<br> * * @param context * @return 当前应用的版本名称 */ public static String getVersionName(Context context) { try { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block Logger.d(TAG, e.toString()); } return null; }
/** * Gets the activity or application icon for an activity. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the acitivy or the application have an icon set. */ private Drawable getActivityIcon(ComponentName component) { PackageManager pm = mContext.getPackageManager(); final ActivityInfo activityInfo; try { activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA); } catch (NameNotFoundException ex) { Log.w(LOG_TAG, ex.toString()); return null; } int iconId = activityInfo.getIconResource(); if (iconId == 0) return null; String pkg = component.getPackageName(); Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo); if (drawable == null) { Log.w( LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString()); return null; } return drawable; }
@Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) { mCursor.moveToPosition(position); String packagename = mCursor.getString(mCursor.getColumnIndex(AppData.App.PKG_NAME)); ApplicationInfo applicationInfo = null; AppInfo appInfo = null; try { applicationInfo = pm.getApplicationInfo(packagename, 0); appInfo = new AppInfo(getActivity(), applicationInfo); appInfo.setPackageName(packagename); appInfo.setAppIcon(applicationInfo.loadIcon(pm)); appInfo.loadLabel(); appInfo.loadVersion(); showMenuDialog(appInfo, arg1); } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } return true; }
/** Setup the layout graphical items based on the current theme. */ private void setupLayoutTheme() { if (_debug) Log.v("ThemeView.setupLayoutTheme() _themePackageName: " + _themePackageName); Drawable layoutBackgroundDrawable = null; Drawable rescheduleDrawable = null; Drawable ttsDrawable = null; int notificationCountTextColorID = 0; int headerInfoTextcolorID = 0; int contactNameTextColorID = 0; int contactNumberTextColorID = 0; int bodyTextColorID = 0; int buttonTextColorID = 0; String themeName = null; if (_themePackageName.startsWith(Constants.DARK_TRANSLUCENT_THEME)) { _resources = _context.getResources(); if (_themePackageName.equals(Constants.DARK_TRANSLUCENT_THEME)) { layoutBackgroundDrawable = _resources.getDrawable(R.drawable.background_panel); themeName = _context.getString(R.string.notify_theme) + " - " + _context.getString(R.string.default_v1); } else if (_themePackageName.equals(Constants.DARK_TRANSLUCENT_V2_THEME)) { layoutBackgroundDrawable = _resources.getDrawable(R.drawable.background_panel_v2); themeName = _context.getString(R.string.notify_theme) + " - " + _context.getString(R.string.default_v2); } else if (_themePackageName.equals(Constants.DARK_TRANSLUCENT_V3_THEME)) { layoutBackgroundDrawable = _resources.getDrawable(R.drawable.background_panel_v3); themeName = _context.getString(R.string.notify_theme) + " - " + _context.getString(R.string.default_v3); } rescheduleDrawable = _resources.getDrawable(R.drawable.ic_reschedule); ttsDrawable = _resources.getDrawable(R.drawable.ic_tts); notificationCountTextColorID = _resources.getColor(R.color.notification_count_text_color); headerInfoTextcolorID = _resources.getColor(R.color.header_info_text_color); contactNameTextColorID = _resources.getColor(R.color.contact_name_text_color); contactNumberTextColorID = _resources.getColor(R.color.contact_number_text_color); bodyTextColorID = _resources.getColor(R.color.body_text_color); buttonTextColorID = _resources.getColor(R.color.button_text_color); } else { try { _resources = _context.getPackageManager().getResourcesForApplication(_themePackageName); layoutBackgroundDrawable = _resources.getDrawable( _resources.getIdentifier( _themePackageName + ":drawable/background_panel", null, null)); rescheduleDrawable = _resources.getDrawable( _resources.getIdentifier( _themePackageName + ":drawable/ic_reschedule", null, null)); ttsDrawable = _resources.getDrawable( _resources.getIdentifier(_themePackageName + ":drawable/ic_tts", null, null)); notificationCountTextColorID = _resources.getColor( _resources.getIdentifier( _themePackageName + ":color/notification_count_text_color", null, null)); headerInfoTextcolorID = _resources.getColor( _resources.getIdentifier( _themePackageName + ":color/header_info_text_color", null, null)); contactNameTextColorID = _resources.getColor( _resources.getIdentifier( _themePackageName + ":color/contact_name_text_color", null, null)); contactNumberTextColorID = _resources.getColor( _resources.getIdentifier( _themePackageName + ":color/contact_number_text_color", null, null)); bodyTextColorID = _resources.getColor( _resources.getIdentifier(_themePackageName + ":color/body_text_color", null, null)); buttonTextColorID = _resources.getColor( _resources.getIdentifier( _themePackageName + ":color/button_text_color", null, null)); themeName = _resources.getString( _resources.getIdentifier(_themePackageName + ":string/app_name_desc", null, null)); } catch (NameNotFoundException ex) { Log.e("ThemeView.setupLayoutTheme() Loading Theme Package ERROR: " + ex.toString()); _themePackageName = Constants.DARK_TRANSLUCENT_THEME; _resources = _context.getResources(); layoutBackgroundDrawable = _resources.getDrawable(R.drawable.background_panel); rescheduleDrawable = _resources.getDrawable(R.drawable.ic_reschedule); ttsDrawable = _resources.getDrawable(R.drawable.ic_tts); notificationCountTextColorID = _resources.getColor(R.color.notification_count_text_color); headerInfoTextcolorID = _resources.getColor(R.color.header_info_text_color); contactNameTextColorID = _resources.getColor(R.color.contact_name_text_color); contactNumberTextColorID = _resources.getColor(R.color.contact_number_text_color); bodyTextColorID = _resources.getColor(R.color.body_text_color); buttonTextColorID = _resources.getColor(R.color.button_text_color); themeName = _context.getString(R.string.notify_theme) + " - " + _context.getString(R.string.default_v1); } } _notificationWindowLinearLayout.setBackgroundDrawable(layoutBackgroundDrawable); _notificationCountTextView.setTextColor(notificationCountTextColorID); _notificationInfoTextView.setTextColor(headerInfoTextcolorID); _contactNameTextView.setTextColor(contactNameTextColorID); _contactNumberTextView.setTextColor(contactNumberTextColorID); _notificationDetailsTextView.setTextColor(bodyTextColorID); _notificationDetailsTextView.setLinkTextColor(bodyTextColorID); _mmsLinkTextView.setTextColor(bodyTextColorID); _previousButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NAV_PREV)); _nextButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NAV_NEXT)); _dismissButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _deleteButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _callButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _replyButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _viewButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _dismissButton.setTextColor(buttonTextColorID); _deleteButton.setTextColor(buttonTextColorID); _callButton.setTextColor(buttonTextColorID); _replyButton.setTextColor(buttonTextColorID); _viewButton.setTextColor(buttonTextColorID); _dismissImageButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _deleteImageButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _callImageButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _replyImageButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _viewImageButton.setBackgroundDrawable(getThemeButton(Constants.THEME_BUTTON_NORMAL)); _rescheduleButton.setImageDrawable(rescheduleDrawable); _ttsButton.setImageDrawable(ttsDrawable); _themeNameTextView.setText(themeName); }