List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:Main.java
public static String getAppVersion(Context c, @SuppressWarnings("rawtypes") Class cls) { try {// w w w. j a va2 s . c om ComponentName comp = new ComponentName(c, cls); PackageInfo pinfo = c.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionName; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return null; } }
From source file:Main.java
/** * Restituisce le informazioni relative al package * @param context/*from w w w . j ava 2s. com*/ * @param thisClass * @return */ public static PackageInfo getAppPackageInfo(Context context, Class<?> thisClass) { PackageInfo pinfo = null; try { ComponentName comp = new ComponentName(context, thisClass); pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); } catch (Exception e) { } return pinfo; }
From source file:Main.java
/** * Returns Package name of top activity//from ww w . j av a2s . c o m * @param context Context to provide activity information * @return String representing package name of top activity */ public static String getTopActivityPackageName(Context context) { ComponentName activity = getTopActivity(context); if (activity == null) { return null; } return activity.getPackageName(); }
From source file:Main.java
/** Returns Package name of base activity.<p> * Requires GET_TASK permission/*from ww w . ja v a 2s .c o m*/ * @param context Context to get base activity information * @return String containing base package name */ public static String getBaseActivityPackageName(Context context) { ComponentName activity = getBaseActivity(context); if (activity == null) { return null; } return activity.getPackageName(); }
From source file:Main.java
/** * Determines if this application is top activity * @param context Context to be examined * @return true if this application is a top activity; false otherwise *//*from ww w . j av a 2 s .c o m*/ public static boolean isTopApplication(Context context) { ComponentName activity = getTopActivity(context); if (activity == null) { return false; } return activity.getPackageName().equals(context.getApplicationInfo().packageName); }
From source file:Main.java
/** * Fetch the versionCode from the AndroicManifest.xml * /*from w ww. java2 s . c o m*/ * @param context * @return the versionCode */ public static int getVersionCode(Context context) { try { ComponentName comp = new ComponentName(context, context.getClass()); PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionCode; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return 0; } }
From source file:Main.java
/** * Fetch the versionName from the AndroicManifest.xml * /*from ww w .j a va 2s. co m*/ * @param context * @return the versionName */ public static String getVersionName(Context context) { try { ComponentName comp = new ComponentName(context, context.getClass()); PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionName; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return null; } }
From source file:Main.java
/** * Restituisce il numero di versione dell'applicazione * Se il numero di versione (versionName) termina con il carattere punto * allora viene aggiunto anche il numero della build *///from w ww . j a va 2 s . c o m public static String getApplicationVersion(Context context, Class<?> thisClass) { PackageInfo pinfo = null; String version = null; try { ComponentName comp = new ComponentName(context, thisClass); pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); version = pinfo.versionName; if (version.endsWith(".")) version += pinfo.versionCode; } catch (Exception e) { } return version; }
From source file:Main.java
public static boolean checkNotificationReadPermission(Activity activity) { String notiStr = Settings.Secure.getString(activity.getContentResolver(), "enabled_notification_listeners"); if (notiStr != null && !TextUtils.isEmpty(notiStr)) { final String[] names = notiStr.split(":"); for (String name : names) { ComponentName cn = ComponentName.unflattenFromString(name); if (cn != null) { if (activity.getPackageName().equals(cn.getPackageName())) { return true; }//ww w . j av a2s.com } } } return false; }
From source file:org.mozilla.gecko.GeckoActivity.java
private static boolean checkIfGeckoActivity(Intent intent) { // Whenever we call our own activity, the component and its package name is set. // If we call an activity from another package, or an open intent (leaving android to resolve) // component has a different package name or it is null. ComponentName component = intent.getComponent(); return (component != null && AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName())); }