code: public static boolean isInstalledOnSDCard(Application app) {
          try {
              String packageName = app.getPackageName();
              PackageInfo info = app.getPackageManager().getPackageInfo(packageName, 0);
              String dir = info.applicationInfo.sourceDir;
  
              for (String path : INTERNAL_PATH) {
                  if (path.equals(dir.substring(0, path.length())))
                      return false;
              }
          } catch (PackageManager.NameNotFoundException exp) {
              throw new IllegalArgumentException(exp);
          }
          return true;
      }
docs: Checks if the application is installed on external storage, in most case on the SD card.
  @param app the application to check.
  @return true if the application is installed on external storage, false otherwise.