private boolean addAppWidget(
        SQLiteDatabase db, ContentValues values, TypedArray a, PackageManager packageManager) {

      String packageName = a.getString(R.styleable.Favorite_packageName);
      String className = a.getString(R.styleable.Favorite_className);

      if (packageName == null || className == null) {
        return false;
      }

      boolean hasPackage = true;
      ComponentName cn = new ComponentName(packageName, className);
      try {
        packageManager.getReceiverInfo(cn, 0);
      } catch (Exception e) {
        String[] packages =
            packageManager.currentToCanonicalPackageNames(new String[] {packageName});
        cn = new ComponentName(packages[0], className);
        try {
          packageManager.getReceiverInfo(cn, 0);
        } catch (Exception e1) {
          hasPackage = false;
        }
      }

      if (hasPackage) {
        int spanX = a.getInt(R.styleable.Favorite_spanX, 0);
        int spanY = a.getInt(R.styleable.Favorite_spanY, 0);
        return addAppWidget(db, values, cn, spanX, spanY);
      }

      return false;
    }
    private boolean addAppShortcut(
        SQLiteDatabase db,
        ContentValues values,
        TypedArray a,
        PackageManager packageManager,
        Intent intent) {

      ActivityInfo info;
      String packageName = a.getString(R.styleable.Favorite_packageName);
      String className = a.getString(R.styleable.Favorite_className);
      try {
        ComponentName cn;
        try {
          cn = new ComponentName(packageName, className);
          info = packageManager.getActivityInfo(cn, 0);
        } catch (PackageManager.NameNotFoundException nnfe) {
          String[] packages =
              packageManager.currentToCanonicalPackageNames(new String[] {packageName});
          cn = new ComponentName(packages[0], className);
          info = packageManager.getActivityInfo(cn, 0);
        }

        intent.setComponent(cn);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        values.put(Favorites.INTENT, intent.toUri(0));
        values.put(Favorites.TITLE, info.loadLabel(packageManager).toString());
        values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPLICATION);
        values.put(Favorites.SPANX, 1);
        values.put(Favorites.SPANY, 1);
        db.insert(TABLE_FAVORITES, null, values);
      } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Unable to add favorite: " + packageName + "/" + className, e);
        return false;
      }
      return true;
    }