All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.maps.android.PackageManager Maven / Gradle / Ivy

Go to download

Use the Google Maps Platform Web Services in Java! https://developers.google.com/maps/documentation/webservices/

The newest version!
package com.google.maps.android;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/** Wrapper for the Android class android.content.pm.PackageManager. */
public class PackageManager {
  private Class pmClass;
  private Object pmInstance;

  public PackageManager(@NotNull Class pmClass, @NotNull Object pm) {
    this.pmClass = pmClass;
    this.pmInstance = pm;
  }

  /**
   * Similar to PackageInfo#getPackageInfo
   * but performed through reflection.
   *
   * @param packageName the package name
   * @param flags additional flags
   * @return the PackageInfo for the requested package name if found, otherwise, null
   */
  @Nullable
  public PackageInfo getPackageInfo(String packageName, int flags) {
    try {
      final Class piClass = Class.forName("android.content.pm.PackageInfo");
      final Method method = pmClass.getMethod("getPackageInfo", String.class, int.class);
      return new PackageInfo(piClass, method.invoke(pmInstance, packageName, flags));
    } catch (NoSuchMethodException
        | IllegalAccessException
        | InvocationTargetException
        | ClassNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy