List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:com.wbtech.common.CommonUtil.java
/** * PackageName/*from w w w . ja v a2 s . c om*/ * @param context * @return */ public static String getPackageName(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (checkPermissions(context, "android.permission.GET_TASKS")) { ComponentName cn = am.getRunningTasks(1).get(0).topActivity; return cn.getPackageName(); } else { if (UmsConstants.DebugMode) { Log.e("lost permission", "android.permission.GET_TASKS"); } return null; } }
From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java
static String getForeGroundKK(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); // get the info from the currently running task List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()); String s = taskInfo.get(0).topActivity.getClassName(); ComponentName componentInfo = taskInfo.get(0).topActivity; componentInfo.getPackageName(); return componentInfo.getPackageName(); }
From source file:androidx.media.SessionToken2.java
private static String getSessionIdFromService(PackageManager manager, String serviceInterface, ComponentName serviceComponent) { Intent serviceIntent = new Intent(serviceInterface); // Use queryIntentServices to find services with MediaLibraryService2.SERVICE_INTERFACE. // We cannot use resolveService with intent specified class name, because resolveService // ignores actions if Intent.setClassName() is specified. serviceIntent.setPackage(serviceComponent.getPackageName()); List<ResolveInfo> list = manager.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA); if (list != null) { for (int i = 0; i < list.size(); i++) { ResolveInfo resolveInfo = list.get(i); if (resolveInfo == null || resolveInfo.serviceInfo == null) { continue; }// w ww . j av a 2 s.c o m if (TextUtils.equals(resolveInfo.serviceInfo.name, serviceComponent.getClassName())) { return getSessionId(resolveInfo); } } } return null; }
From source file:com.radiusnetworks.scavengerhunt.ScavengerHuntApplication.java
public static boolean isApplicationSentToBackground(final Context context) { if (context != null) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w . j a va 2 s.c om*/ } } return false; }
From source file:androidx.core.app.NotificationManagerCompat.java
/** * Get the set of packages that have an enabled notification listener component within them. *///from w w w . j ava2 s. co m @NonNull public static Set<String> getEnabledListenerPackages(@NonNull Context context) { final String enabledNotificationListeners = Settings.Secure.getString(context.getContentResolver(), SETTING_ENABLED_NOTIFICATION_LISTENERS); synchronized (sEnabledNotificationListenersLock) { // Parse the string again if it is different from the last time this method was called. if (enabledNotificationListeners != null && !enabledNotificationListeners.equals(sEnabledNotificationListeners)) { final String[] components = enabledNotificationListeners.split(":"); Set<String> packageNames = new HashSet<String>(components.length); for (String component : components) { ComponentName componentName = ComponentName.unflattenFromString(component); if (componentName != null) { packageNames.add(componentName.getPackageName()); } } sEnabledNotificationListenerPackages = packageNames; sEnabledNotificationListeners = enabledNotificationListeners; } return sEnabledNotificationListenerPackages; } }
From source file:net.lp.actionbarpoirot.helpers.DualNavUtils.java
/** * Obtain an {@link Intent} that will launch an explicit target activity * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} * <meta-data> element in the application's manifest. * /*w w w.j a va 2 s .c o m*/ * @param context * Context for looking up the activity component for the source * activity * @param componentName * ComponentName for the source Activity * @return a new Intent targeting the defined parent activity of * sourceActivity * @throws NameNotFoundException * if the ComponentName for sourceActivityClass is invalid */ public static Intent getParentActivityIntent(Context context, ComponentName componentName) throws NameNotFoundException { String parentActivity = getParentActivityName(context, componentName); if (parentActivity == null) return null; // If the parent itself has no parent, generate a main activity intent. ComponentName target = new ComponentName(componentName.getPackageName(), parentActivity); String grandparent = null; try { grandparent = getParentActivityName(context, target); } catch (NameNotFoundException e) { // ***ActionBarPoirot // added************************************************************************************************************************************* if (PoirotWindow.DEBUG) e.printStackTrace(); // If this runs in an extension app, then the grandparent search is // going to throw an error. It can be equated with null, so the MAIN // intent is created below. final String mainPackageName = ((ActivityHelperUser) context).getHomePackageName(); if (!mainPackageName.equalsIgnoreCase(componentName.getPackageName()) && componentName.getPackageName().startsWith(mainPackageName)) { target = new ComponentName(mainPackageName, parentActivity); } else { throw e; } } final Intent parentIntent = grandparent == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target); return parentIntent; }
From source file:ch.ethz.dcg.jukefox.commons.utils.AndroidUtils.java
public static String getVersionName() { try {/*from w ww . j a v a2s.c o m*/ Context context = JukefoxApplication.getAppContext(); ComponentName comp = new ComponentName(context, JukefoxApplication.class); PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionName; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return ""; } }
From source file:ch.ethz.dcg.jukefox.commons.utils.AndroidUtils.java
public static int getVersionCode() { try {//from w w w . ja va 2 s. co m Context context = JukefoxApplication.getAppContext(); ComponentName comp = new ComponentName(context, JukefoxApplication.class); PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionCode; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return -1; } }
From source file:com.google.android.apps.dashclock.ExtensionPackageChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { ExtensionManager extensionManager = ExtensionManager.getInstance(context); if (extensionManager.cleanupExtensions()) { LOGD(TAG, "Extension cleanup performed and action taken."); Intent widgetUpdateIntent = new Intent(context, DashClockService.class); widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS); startWakefulService(context, widgetUpdateIntent); }/*from w w w . j a v a 2 s . co m*/ // If this is a replacement or change in the package, update all active extensions from // this package. String action = intent.getAction(); if (Intent.ACTION_PACKAGE_CHANGED.equals(action) || Intent.ACTION_PACKAGE_REPLACED.equals(action)) { String packageName = intent.getData().getSchemeSpecificPart(); if (TextUtils.isEmpty(packageName)) { return; } Set<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames(); for (ComponentName cn : activeExtensions) { if (packageName.equals(cn.getPackageName())) { LOGD(TAG, "Package for extension " + cn + " changed; asking it for an update."); Intent extensionUpdateIntent = new Intent(context, DashClockService.class); extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS); // TODO: UPDATE_REASON_PACKAGE_CHANGED extensionUpdateIntent.putExtra(DashClockService.EXTRA_COMPONENT_NAME, cn.flattenToShortString()); startWakefulService(context, extensionUpdateIntent); } } } }
From source file:com.neal.repairer.ease.receiver.CallReceiver.java
private boolean isRunningForeground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; String currentPackageName = cn.getPackageName(); if (!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(context.getPackageName())) { return true; }/*from www .j a v a2s . c o m*/ return false; }