public static String printKeyHash(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 (PackageManager.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;
  }
Пример #2
0
  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)";
    }
  }
 /** 更新微信包信息 */
 private void updatePackageInfo() {
   try {
     mWechatPackageInfo = getContext().getPackageManager().getPackageInfo(WECHAT_PACKAGENAME, 0);
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
   }
 }
    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;
    }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void setAllowedVpnPackages(Builder builder) {
    boolean atLeastOneAllowedApp = false;
    for (String pkg : mProfile.mAllowedAppsVpn) {
      try {
        if (mProfile.mAllowedAppsVpnAreDisallowed) {
          builder.addDisallowedApplication(pkg);
        } else {
          builder.addAllowedApplication(pkg);
          atLeastOneAllowedApp = true;
        }
      } catch (PackageManager.NameNotFoundException e) {
        mProfile.mAllowedAppsVpn.remove(pkg);
        VpnStatus.logInfo(R.string.app_no_longer_exists, pkg);
      }
    }

    if (!mProfile.mAllowedAppsVpnAreDisallowed && !atLeastOneAllowedApp) {
      VpnStatus.logDebug(R.string.no_allowed_app, getPackageName());
      try {
        builder.addAllowedApplication(getPackageName());
      } catch (PackageManager.NameNotFoundException e) {
        VpnStatus.logError("This should not happen: " + e.getLocalizedMessage());
      }
    }

    if (mProfile.mAllowedAppsVpnAreDisallowed) {
      VpnStatus.logDebug(
          R.string.disallowed_vpn_apps_info, TextUtils.join(", ", mProfile.mAllowedAppsVpn));
    } else {
      VpnStatus.logDebug(
          R.string.allowed_vpn_apps_info, TextUtils.join(", ", mProfile.mAllowedAppsVpn));
    }
  }
Пример #6
0
  @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();
    }
  }
Пример #7
0
  @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;
  }
Пример #8
0
  @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();
          }
        });
  }
Пример #9
0
    @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();
    }
Пример #10
0
 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);
 }
Пример #11
0
  /**
   * 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;
  }
Пример #12
0
  @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();
  }
Пример #13
0
  @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);
  }
  @Override
  public void onCreate() {
    super.onCreate();
    ApplicationInfo appliInfo = null;
    super.onCreate();
    try {
      appliInfo =
          this.getPackageManager()
              .getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(TAG, e.getMessage(), e);
    }
    // get info from manifest, which is generated from fetch.json variables
    String clientId = appliInfo.metaData.getString("com.inbeacon.android.CLIENTID");
    String clientSecret = appliInfo.metaData.getString("com.inbeacon.android.SECRET");

    if (clientId == null
        || clientId.equals("your-clientid")
        || clientSecret == null
        || clientSecret.equals("your-secret")) {
      Log.e(
          TAG,
          "Invalid clientId and/or clientSecret !!!!!! YOU NEED TO SET INBEACON CREDENTIALS in your plugin variables (fetch.json)");
      return;
    }
    // initialize the shared instance on application level
    InbeaconManager.initialize(this, clientId, clientSecret);
  }
Пример #15
0
 @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
  public void uncaughtException(Thread thread, Throwable ex) {
    if (this.defaultUncaughtExceptionHandler != null) {
      if (mContext != null) {
        PackageManager manager = mContext.getPackageManager();
        PackageInfo info = null;
        try {
          info = manager.getPackageInfo(mContext.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
          Log.e("error", e.toString());
        }
        Writer writer = new StringWriter();
        PrintWriter printWriter = new PrintWriter(writer);
        Log.e("info", printWriter.toString());

        // at this point we can log into local files and send information to crashlytics and other
        // stuffs
        final AlarmServiceVo userDataCollectorServiceVo =
            new AlarmServiceVo(
                Constants.AlarmManager.AlarmManagerRequestCode.COLLECT_USER_DATA,
                Constants.AlarmManager.COLLECT_USER_DATA_DELAY_MILLISECONDS,
                Constants.AlarmManager.COLLECT_USER_DATA_PERIODIC_TIME_MILLISECONDS);
        new UserDataAlarmManager(mContext, PointwiseService.class)
            .setUpAlarmManager(userDataCollectorServiceVo);

        final AlarmServiceVo userDataPeekerServiceVo =
            new AlarmServiceVo(
                Constants.AlarmManager.AlarmManagerRequestCode.PEEK_USER_DATA,
                Constants.AlarmManager.PEEK_USER_DATA_DELAY_MILLISECONDS,
                Constants.AlarmManager.PEEK_USER_DATA_PERIODIC_TIME_MILLISECONDS);
        new UserDataAlarmManager(mContext, PointwiseSyncService.class)
            .setUpAlarmManager(userDataPeekerServiceVo);
      }
    }
  }
Пример #17
0
 public AboutDialogFragment() {
   try {
     mPackageInfo =
         getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
   }
 }
Пример #18
0
 /*
  * 获取程序 图标
  */
 public Drawable getAppIcon(String packname) {
   try {
     ApplicationInfo info = pm.getApplicationInfo(packname, 0);
     return info.loadIcon(pm);
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
   }
   return null;
 }
Пример #19
0
 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;
 }
Пример #20
0
 /*
  * 获取程序的名字
  */
 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;
 }
 private void setVersion() {
   try {
     PackageInfo packageInfo =
         getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
     setText(packageInfo.versionName);
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
   }
 }
Пример #22
0
 /**
  * 判断当前程序的版本号
  *
  * @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;
 }
Пример #23
0
 private String getVersion() {
   try {
     PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0);
     return p.versionName;
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
     return "1.0";
   }
 }
Пример #24
0
 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);
 }
Пример #25
0
 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);
   }
 }
Пример #26
0
 /**
  * 获取当前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;
 }
Пример #27
0
 /**
  * 获取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;
 }
 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();
   }
 }
Пример #29
0
 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;
 }
Пример #30
0
  /*
   *获取程序的版本号
   */
  public String getAppVersion(String packname) {

    try {
      PackageInfo packinfo = pm.getPackageInfo(packname, 0);
      return packinfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }