@Override protected Call enqueue(Request request, com.squareup.okhttp.Callback requestCallback) { Context context = PopcornApplication.getAppContext(); PackageInfo pInfo; String versionName = "0.0.0"; try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionName = pInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } request = request .newBuilder() .removeHeader("User-Agent") .addHeader( "User-Agent", String.format( "Mozilla/5.0 (Linux; U; Android %s; %s; %s Build/%s) AppleWebkit/534.30 (KHTML, like Gecko) PT/%s", Build.VERSION.RELEASE, LocaleUtils.getCurrent(), Build.MODEL, Build.DISPLAY, versionName)) .build(); return super.enqueue(request, requestCallback); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_student_guanyu); context = this; TextView titletext = (TextView) findViewById(R.id.title_text); titletext.setText("关于师课家教宝"); findViewById(R.id.gongneng_jieshao_btn).setOnClickListener(listener); findViewById(R.id.faq_btn).setOnClickListener(listener); findViewById(R.id.wenti_fankui_btn).setOnClickListener(listener); findViewById(R.id.left_btn).setOnClickListener(listener); PackageManager packageManager = getPackageManager(); // getPackageName()是你当前类的包名,0代表是获取版本信息 PackageInfo packInfo = null; try { packInfo = packageManager.getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String localVersion = packInfo.versionName; TextView versiontext = (TextView) findViewById(R.id.ver_name); versiontext.setText("当前版本: V" + localVersion); Sofy_Info(); }
/** * Checks SHA1 fingerprint of the enabler * * @return true if signature matches, false if package is not found or signature does not match. */ private boolean verifyFingreprint() { try { PackageInfo info = context .getPackageManager() .getPackageInfo(NOKIA_INSTALLER, PackageManager.GET_SIGNATURES); if (info.signatures.length == 1) { byte[] cert = info.signatures[0].toByteArray(); MessageDigest digest; digest = MessageDigest.getInstance("SHA1"); byte[] ENABLER_FINGERPRINT = digest.digest(cert); byte[] EXPECTED_FINGERPRINT = hexStringToByteArray(EXPECTED_SHA1_FINGERPRINT); if (Arrays.equals(ENABLER_FINGERPRINT, EXPECTED_FINGERPRINT)) { Logger.i("isBillingAvailable", "NIAP signature verified"); return true; } } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return false; }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View content = inflater.inflate(R.layout.dialog_about, null, false); TextView version = (TextView) content.findViewById(R.id.version); try { String name = getActivity() .getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0) .versionName; version.setText(getString(R.string.version) + " " + name); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return new AlertDialog.Builder(getActivity()) .setTitle(R.string.app_name) .setView(content) .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }) .create(); }
public static String getCertFingerprint(Context context) { try { @SuppressLint("PackageManagerGetSignatures") Signature[] sigs = context .getPackageManager() .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES) .signatures; if (sigs.length == 0) { return "ERROR: NO SIGNATURE."; } else if (sigs.length > 1) { return "ERROR: MULTIPLE SIGNATURES"; } byte[] digest = MessageDigest.getInstance("SHA1").digest(sigs[0].toByteArray()); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < digest.length; ++i) { if (i > 0) { hexString.append(":"); } byteToString(hexString, digest[i]); } return hexString.toString(); } catch (PackageManager.NameNotFoundException ex) { ex.printStackTrace(); return "(ERROR: package not found)"; } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); return "(ERROR: SHA1 algorithm not found)"; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); mToolbar = (Toolbar) findViewById(R.id.toolbar); // 初始化Toolbar setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // 获取APP版本号(名) try { TextView versionView = (TextView) findViewById(R.id.about_version); PackageManager packageManager = getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); versionView.setText("V" + packageInfo.versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } mToolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); }
private void init(Context ctx) { ApplicationInfo appInfo = null; try { appInfo = ctx.getPackageManager() .getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String appKey; String appSecret; if (appInfo.metaData == null || appInfo.metaData.getString("SMS_MOB_APPKEY") == null || appInfo.metaData.getString("SMS_MOB_APPSECRET") == null) { appKey = DEFAULT_APPKEY; appSecret = DEFAULT_APPSECRET; } else { appKey = appInfo.metaData.getString("SMS_MOB_APPKEY").trim(); appSecret = appInfo.metaData.getString("SMS_MOB_APPSECRET").trim(); } log("appkey:" + appKey + " appsecret:" + appSecret); SMSSDK.initSDK(ctx, appKey, appSecret); inited = true; SMSSDK.registerEventHandler(mHandler); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); SharedPreferences p = MultiROMMgrApplication.getPreferences(); if (p.getString(GENERAL_DOWNLOAD_DIR, null) == null) Utils.setDownloadDir(Utils.getDefaultDownloadDir()); addPreferencesFromResource(R.xml.settings); addDevOptions(); p.registerOnSharedPreferenceChangeListener(this); updatePrefText(); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); Preference pref = findPreference(ABOUT_VERSION); pref.setSummary(pInfo.versionName); pref.setOnPreferenceClickListener(this); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Preference pref = findPreference(ABOUT_LICENSES); pref.setOnPreferenceClickListener(this); }
private long addPackage(List<AppsListItem> apps, PackageStats pStats, boolean succeeded) { long cacheSize = pStats.cacheSize; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { cacheSize += pStats.externalCacheSize; } if (!succeeded || cacheSize <= 0) { return 0; } try { PackageManager packageManager = getPackageManager(); ApplicationInfo info = packageManager.getApplicationInfo(pStats.packageName, PackageManager.GET_META_DATA); apps.add( new AppsListItem( pStats.packageName, packageManager.getApplicationLabel(info).toString(), packageManager.getApplicationIcon(pStats.packageName), cacheSize)); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return cacheSize; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); context = getActivity(); storagePath = findPreference("prefStoragePath"); storagePath.setOnPreferenceClickListener(this); update = findPreference("prefUpdate"); update.setOnPreferenceClickListener(this); privacy = findPreference("prefPrivacy"); privacy.setOnPreferenceClickListener(this); terms = findPreference("prefTOS"); terms.setOnPreferenceClickListener(this); facebook = findPreference("prefFacebook"); facebook.setOnPreferenceClickListener(this); googlePlus = findPreference("prefGooglePlus"); googlePlus.setOnPreferenceClickListener(this); madeWithLove = findPreference("prefMadeWithLove"); madeWithLove.setOnPreferenceClickListener(this); about = findPreference("prefAboutApp"); about.setOnPreferenceClickListener(this); storagePath.setSummary(Utils.getStoragePath(getActivity())); try { PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); findPreference("prefAppVersion").setSummary(pInfo.versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.share_intent_row, parent, false); ImageView appIcon = (ImageView) rowView.findViewById(R.id.share_intent_icon); TextView appName = (TextView) rowView.findViewById(R.id.share_intent_name); Intent item = shareIntents.get(position); String appPackage = item.getStringExtra("packageName"); String appPackageName = item.getStringExtra("appName"); Drawable appPackageIcon = null; try { appPackageIcon = mContext.getPackageManager().getApplicationIcon(appPackage); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } if (appPackageIcon != null) { appIcon.setImageDrawable(appPackageIcon); } else { Picasso.with(mContext) .load(R.drawable.placeholeder_lowres) .transform(new CircleTransform()) .into(appIcon); } appName.setText(appPackageName); return rowView; }
/** 更新微信包信息 */ private void updatePackageInfo() { try { mWechatPackageInfo = getContext().getPackageManager().getPackageInfo(WECHAT_PACKAGENAME, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
public AboutDialogFragment() { try { mPackageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
public static int getAppVersion(Context context) { try { PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return 1; }
private String getVersion() { try { PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0); return p.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return "1.0"; } }
private void setVersion() { try { PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); setText(packageInfo.versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
/* * 获取程序 图标 */ public Drawable getAppIcon(String packname) { try { ApplicationInfo info = pm.getApplicationInfo(packname, 0); return info.loadIcon(pm); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
/** * 判断当前程序的版本号 * * @param context * @return */ public static String getAppVersion(Context context) { String version = "0"; try { version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return version; }
/* * 获取程序的名字 */ public String getAppName(String packname) { try { ApplicationInfo info = pm.getApplicationInfo(packname, 0); return info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
public String getVersionName() { try { PackageManager pm = getPackageManager(); PackageInfo pi = pm.getPackageInfo(getPackageName(), 0); return pi.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return ""; } }
/** * 获取App安装包信息 * * @return */ public PackageInfo getPackageInfo() { PackageInfo info = null; try { info = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(System.err); } if (info == null) info = new PackageInfo(); return info; }
public static Drd_version New(Context context) { PackageManager manager = context.getPackageManager(); PackageInfo info = null; try { info = manager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return new Drd_version(info.versionCode, info.versionName); }
public static PackageInfo getAPKVersionInfo(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); PackageInfo packInfo = null; try { packInfo = packageManager.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packInfo; }
/** * 获取当前App信息 * * <p>AppInfo(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序) */ public static AppInfo getAppInfo(Context context) { PackageManager pm = context.getPackageManager(); PackageInfo pi = null; try { pi = pm.getPackageInfo(context.getApplicationContext().getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return pi != null ? getBean(pm, pi) : null; }
/* *获取程序的版本号 */ public String getAppVersion(String packname) { try { PackageInfo packinfo = pm.getPackageInfo(packname, 0); return packinfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
public static Drawable getAppIcon(Context ctx, String pkgName) { // PackageInfo pi = ctx.getPackageManager().getPackageInfo(pkgName, // PackageManager.GET_ACTIVITIES); try { return ctx.getPackageManager().getApplicationIcon(pkgName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return ctx.getResources().getDrawable(R.mipmap.bg); } }
private void initData() { PackageManager pm = getPackageManager(); try { PackageInfo packageInfo = pm.getPackageInfo(packname, 0); Drawable icon = packageInfo.applicationInfo.loadIcon(pm); iv_icon.setImageDrawable(icon); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
private void showInstallNotification(ScanResult result) { if (result != null) { PackageInfo pi = null; PackageManager pm = getApplicationContext().getPackageManager(); try { pi = pm.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String appName = pm.getApplicationLabel(pi.applicationInfo).toString(); if (result.dangerCount.equals(0)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_is_safe)) .setContentText(getString(R.string.open_app)) .setAutoCancel(true); Intent resultIntent = pm.getLaunchIntentForPackage(packageName); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_unsafe)) .setContentText(getString(R.string.click_show_result)) .setAutoCancel(true); Intent resultIntent = new Intent(getBaseContext(), ResultActivity.class); // resultIntent.putExtra("CALLED_FROM", ScanService.class.getName()); Bundle bundle = new Bundle(); bundle.putParcelable("SCAN_RESULT", result); resultIntent.putExtras(bundle); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } } }
/** 앱으로부터 알아낸 버젼. */ public String getAppVersionForApp() { PackageInfo pInfo = null; try { pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); String version = pInfo.versionName; return version; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return ""; }
public static String getInstalledWhatsAppVersion(Context context) { String version = ""; try { version = context.getPackageManager().getPackageInfo("com.whatsapp", 0).versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return version; }