android.content.pm.ResolveInfo Java Examples

The following examples show how to use android.content.pm.ResolveInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppPickerPreference.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
public ShortcutItem(String appName, ResolveInfo ri) {
    mAppName = appName;
    mResolveInfo = ri;
    if (mResolveInfo != null) {
        mCreateShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
        ComponentName cn = new ComponentName(mResolveInfo.activityInfo.packageName,
                mResolveInfo.activityInfo.name);
        mCreateShortcutIntent.setComponent(cn);
        // mark intent so we can later identify it comes from GB
        mCreateShortcutIntent.putExtra("gravitybox", true);
        if (mAllowUnlockAction) {
            mCreateShortcutIntent.putExtra(ShortcutActivity.EXTRA_ALLOW_UNLOCK_ACTION, true);
        }
        if (mLaunchesFromLockscreen) {
            mCreateShortcutIntent.putExtra(ShortcutActivity.EXTRA_LAUNCHES_FROM_LOCKSCREEN, true);
        }
    }
}
 
Example #2
Source File: ActivityManagerProxy.java    From VirtualAPK with Apache License 2.0 6 votes vote down vote up
protected void getIntentSender(Method method, Object[] args) {
    String hostPackageName = mPluginManager.getHostContext().getPackageName();
    args[1] = hostPackageName;

    Intent target = ((Intent[]) args[5])[0];
    int intentSenderType = (int)args[0];
    if (intentSenderType == INTENT_SENDER_ACTIVITY) {
        mPluginManager.getComponentsHandler().transformIntentToExplicitAsNeeded(target);
        mPluginManager.getComponentsHandler().markIntentIfNeeded(target);
    } else if (intentSenderType == INTENT_SENDER_SERVICE) {
        ResolveInfo resolveInfo = this.mPluginManager.resolveService(target, 0);
        if (resolveInfo != null && resolveInfo.serviceInfo != null) {
            // find plugin service
            Intent wrapperIntent  = wrapperTargetIntent(target, resolveInfo.serviceInfo, null, RemoteService.EXTRA_COMMAND_START_SERVICE);
            ((Intent[]) args[5])[0] = wrapperIntent;
        }
    } else if (intentSenderType == INTENT_SENDER_BROADCAST) {
        // no action
    }
}
 
Example #3
Source File: NativeProtocol.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
static Intent validateKatanaServiceIntent(Context context, Intent intent) {
    if (intent == null) {
        return null;
    }

    ResolveInfo resolveInfo = context.getPackageManager().resolveService(intent, 0);
    if (resolveInfo == null) {
        return null;
    }

    if (!validateSignature(context, resolveInfo.serviceInfo.packageName)) {
        return null;
    }

    return intent;
}
 
Example #4
Source File: AwoPatchReceiver.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void restart() {
    Intent
        intent = RuntimeVariables.androidApplication.getPackageManager().getLaunchIntentForPackage(RuntimeVariables.androidApplication.getPackageName());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_NEW_TASK);
    ResolveInfo info = RuntimeVariables.androidApplication.getPackageManager().resolveActivity(intent, 0);
    if (info != null) {
        Log.d("PatchReceiver", info.activityInfo.name);
    } else {
        Log.d("PatchReceiver", "no activity");

    }
    // RuntimeVariables.androidApplication.startActivity(intent);
    kill();
    android.os.Process.killProcess(android.os.Process.myPid());
    // System.exit(0);
}
 
Example #5
Source File: PulltorefreshSwipeTest.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
private void open(ApplicationInfo item) {
    // open app
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(item.packageName);
    List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(resolveIntent, 0);
    if (resolveInfoList != null && resolveInfoList.size() > 0) {
        ResolveInfo resolveInfo = resolveInfoList.get(0);
        String activityPackageName = resolveInfo.activityInfo.packageName;
        String className = resolveInfo.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName componentName = new ComponentName(activityPackageName, className);

        intent.setComponent(componentName);
        startActivity(intent);
    }
}
 
Example #6
Source File: AppInfoEngine.java    From AppPlus with MIT License 6 votes vote down vote up
/**
 * get recent running app list
 * @return recent running app list
 */
@Deprecated
public List<AppEntity> getRecentAppList() {
    List<AppEntity> list = new ArrayList<>();
    ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RecentTaskInfo> recentTasks = mActivityManager.getRecentTasks(10, 0);
    for (ActivityManager.RecentTaskInfo taskInfo : recentTasks) {
        Intent intent = taskInfo.baseIntent;
        ResolveInfo resolveInfo = mPackageManager.resolveActivity(intent, 0);
        if (resolveInfo == null)continue;
        String packageName = resolveInfo.activityInfo.packageName;
        if (isSystemApp(packageName)) continue;
        if (isShowSelf(packageName)) continue;
        AppEntity appEntity = DataHelper.getAppByPackageName(packageName);
        if (appEntity == null)continue;
        list.add (appEntity);
    }
    return list;
}
 
Example #7
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
		IAccountParser accountParser) {
	for (ResolveInfo info : services) {
		XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
				AccountManager.AUTHENTICATOR_META_DATA_NAME);
		if (parser != null) {
			try {
				AttributeSet attributeSet = Xml.asAttributeSet(parser);
				int type;
				while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
					// Nothing to do
				}
				if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
					AuthenticatorDescription desc = parseAuthenticatorDescription(
							accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
							info.serviceInfo.packageName, attributeSet);
					if (desc != null) {
						map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example #8
Source File: GenerateShortcutHelper.java    From TvAppRepo with Apache License 2.0 6 votes vote down vote up
public static void begin(final Activity activity, final ResolveInfo resolveInfo) {
    new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.dialog_theme))
            .setTitle(activity.getString(R.string.title_shortcut_generator,
                    resolveInfo.activityInfo.applicationInfo.loadLabel(activity.getPackageManager())))
            .setMessage(R.string.shortcut_generator_info)
            .setPositiveButton(R.string.create_shortcut, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    generateShortcut(activity, resolveInfo);
                }
            })
            .setNeutralButton(R.string.advanced, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Open a new dialog
                    openAdvancedOptions(activity, resolveInfo);
                }
            })
            .setNegativeButton(R.string.cancel, null)
            .show();
}
 
Example #9
Source File: CropImage.java    From Lassi-Android with MIT License 6 votes vote down vote up
/**
 * Get all Camera intents for capturing image using device camera apps.
 */
public static List<Intent> getCameraIntents(
        @NonNull Context context, @NonNull PackageManager packageManager) {

    List<Intent> allIntents = new ArrayList<>();

    // Determine Uri of camera image to  save.
    Uri outputFileUri = getCaptureImageOutputUri(context);

    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(res.activityInfo.packageName);
        if (outputFileUri != null) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        }
        allIntents.add(intent);
    }

    return allIntents;
}
 
Example #10
Source File: ShareChooserDialog.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    parentWidth = getArguments().getInt(ARG_WIDTH, 640);
    shareIntent = getArguments().getParcelable(ARG_INTENT);
    showNearby = getArguments().getBoolean(ARG_SHOW_NEARBY, false);
    targets = new ArrayList<>();
    List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentActivities(shareIntent, 0);
    if (resInfo != null && resInfo.size() > 0) {
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            if (!packageName.equals(BuildConfig.APPLICATION_ID)) { // Remove ourselves
                targets.add(resolveInfo);
            }
        }
    }
}
 
Example #11
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
    try {
        ParceledListSlice<ResolveInfo> parceledList =
                mPM.queryIntentServices(intent,
                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                flags, userId);
        if (parceledList == null) {
            return Collections.emptyList();
        }
        return parceledList.getList();
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #12
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
@Override
@SuppressWarnings("unchecked")
public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
    try {
        ParceledListSlice<ResolveInfo> parceledList =
                mPM.queryIntentReceivers(intent,
                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                        flags,  userId);
        if (parceledList == null) {
            return Collections.emptyList();
        }
        return parceledList.getList();
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #13
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
@Override
@SuppressWarnings("unchecked")
public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
    try {
        ParceledListSlice<ResolveInfo> parceledList =
                mPM.queryIntentReceivers(intent,
                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                        flags,  userId);
        if (parceledList == null) {
            return Collections.emptyList();
        }
        return parceledList.getList();
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #14
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Intialize the menu items for processing text, if there is any.
 */
private void initializeTextProcessingMenu(Menu menu) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
            || !isSelectActionModeAllowed(MENU_ITEM_PROCESS_TEXT)) {
        return;
    }

    PackageManager packageManager = mContext.getPackageManager();
    List<ResolveInfo> supportedActivities =
            packageManager.queryIntentActivities(createProcessTextIntent(), 0);
    for (int i = 0; i < supportedActivities.size(); i++) {
        ResolveInfo resolveInfo = supportedActivities.get(i);
        CharSequence label = resolveInfo.loadLabel(mContext.getPackageManager());
        menu.add(R.id.select_action_menu_text_processing_menus, Menu.NONE,
                MENU_ITEM_ORDER_TEXT_PROCESS_START + i, label)
                .setIntent(createProcessTextIntentForResolveInfo(resolveInfo))
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}
 
Example #15
Source File: DeviceAdmins.java    From island with Apache License 2.0 6 votes vote down vote up
private static ComponentName queryComponentName(final Context context) {
	final List<ComponentName> active_admins = requireNonNull((DevicePolicyManager) context.getSystemService(DEVICE_POLICY_SERVICE)).getActiveAdmins();
	if (active_admins != null && ! active_admins.isEmpty()) for (final ComponentName active_admin : active_admins)
		if (Modules.MODULE_ENGINE.equals(active_admin.getPackageName())) return active_admin;

	final Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED).setPackage(Modules.MODULE_ENGINE);
	final List<ResolveInfo> admins = context.getPackageManager().queryBroadcastReceivers(intent, PackageManager.GET_DISABLED_COMPONENTS);
	if (admins.size() == 1) {
		final ResolveInfo admin = admins.get(0);
		sDeviceAdminComponent = new ComponentName(Modules.MODULE_ENGINE, admins.get(0).activityInfo.name);
		if (! admin.activityInfo.enabled) {
			Analytics.$().event("device_admin_component_disabled").with(ITEM_ID, sDeviceAdminComponent.flattenToShortString()).send();
			context.getPackageManager().setComponentEnabledSetting(sDeviceAdminComponent, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP);
		}
		return sDeviceAdminComponent;
	}	// No resolve result on some Android 7.x devices, cause unknown.
	if (BuildConfig.DEBUG) throw new IllegalStateException("Engine module is not correctly installed: " + admins);
	return new ComponentName(Modules.MODULE_ENGINE, "com.oasisfeng.island.IslandDeviceAdminReceiver");	// Fallback
}
 
Example #16
Source File: Reddit.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
public static HashMap<String, String> getInstalledBrowsers() {
    int packageMatcher =
            SDK_INT >= M ? PackageManager.MATCH_ALL : PackageManager.GET_DISABLED_COMPONENTS;

    HashMap<String, String> browserMap = new HashMap<>();

    final List<ResolveInfo> resolveInfoList = getAppContext().getPackageManager()
            .queryIntentActivities(
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://ccrama.me")),
                    packageMatcher);

    for (ResolveInfo resolveInfo : resolveInfoList) {
        if (resolveInfo.activityInfo.enabled) {
            browserMap.put(resolveInfo.activityInfo.applicationInfo.packageName,
                    Reddit.getAppContext()
                            .getPackageManager()
                            .getApplicationLabel(resolveInfo.activityInfo.applicationInfo)
                            .toString());
        }
    }

    return browserMap;
}
 
Example #17
Source File: AppUtil.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
/**
 * 通过adb启动应用
 * @param appPackage
 * @return
 */
public static boolean startApp(String appPackage) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(appPackage);
    List<ResolveInfo> resolveInfos = LauncherApplication.getContext().getPackageManager().queryIntentActivities(intent, 0);
    if (resolveInfos == null || resolveInfos.size() == 0) {
        return false;
    }

    // 多Launcher情景
    for (ResolveInfo resolveInfo : resolveInfos) {
        LogUtil.d(TAG, "resolveInfo:" + resolveInfo);
    }
    String targetActivity = resolveInfos.get(0).activityInfo.name;
    CmdTools.execAdbCmd("am start -n '" + appPackage + "/" + targetActivity + "'", 2000);
    return true;
}
 
Example #18
Source File: IntentIntegrator.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean contains(Iterable<ResolveInfo> availableApps, String targetApp) {
  for (ResolveInfo availableApp : availableApps) {
    String packageName = availableApp.activityInfo.packageName;
    if (targetApp.equals(packageName)) {
      return true;
    }
  }
  return false;
}
 
Example #19
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<ResolveInfo> queryIntentActivityOptions(
    ComponentName caller, Intent[] specifics, Intent intent,
    int flags) {
    final ContentResolver resolver = mContext.getContentResolver();

    String[] specificTypes = null;
    if (specifics != null) {
        final int N = specifics.length;
        for (int i=0; i<N; i++) {
            Intent sp = specifics[i];
            if (sp != null) {
                String t = sp.resolveTypeIfNeeded(resolver);
                if (t != null) {
                    if (specificTypes == null) {
                        specificTypes = new String[N];
                    }
                    specificTypes[i] = t;
                }
            }
        }
    }

    try {
        ParceledListSlice<ResolveInfo> parceledList =
                mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
                intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
        if (parceledList == null) {
            return Collections.emptyList();
        }
        return parceledList.getList();
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #20
Source File: CBrowserWindow.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean checkInstallApp(Context context, Intent target) {
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(target,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (null != list && list.size() > 0) {
        return true;
    }
    return false;
}
 
Example #21
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public void onAppPicked(ResolveInfo info) {
    final Intent intent = new Intent(getIntent());
    intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    intent.setComponent(new ComponentName(
            info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
    startActivityForResult(intent, CODE_FORWARD);
}
 
Example #22
Source File: ContextUtils.java    From WayHoo with Apache License 2.0 5 votes vote down vote up
public static Intent getActivityIntent(Context context, String packageName,
		String className) {
	PackageManager pm = context.getPackageManager();
	Intent intent = new Intent();
	ComponentName compoentName = new ComponentName(packageName, className);
	intent.setComponent(compoentName);
	ResolveInfo ri = pm.resolveActivity(intent,
			PackageManager.MATCH_DEFAULT_ONLY);
	if (ri != null) {
		return intent;
	}
	return null;
}
 
Example #23
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable getActivityLogo(Intent intent)
        throws NameNotFoundException {
    if (intent.getComponent() != null) {
        return getActivityLogo(intent.getComponent());
    }

    ResolveInfo info = resolveActivity(
        intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (info != null) {
        return info.activityInfo.loadLogo(this);
    }

    throw new NameNotFoundException(intent.toUri(0));
}
 
Example #24
Source File: TwaProviderPickerTest.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
private void installBrowser(String packageName) {
    Intent intent = new Intent()
            .setData(Uri.fromParts("http", "", null))
            .setAction(Intent.ACTION_VIEW)
            .addCategory(Intent.CATEGORY_BROWSABLE);

    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.activityInfo = new ActivityInfo();
    resolveInfo.activityInfo.packageName = packageName;

    mShadowPackageManager.addResolveInfoForIntent(intent, resolveInfo);
}
 
Example #25
Source File: ShareDialogAdapter.java    From delion with Apache License 2.0 5 votes vote down vote up
private Drawable loadIconForResolveInfo(ResolveInfo info) {
    try {
        final int iconRes = info.getIconResource();
        if (iconRes != 0) {
            Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName);
            Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes);
            return icon;
        }
    } catch (NameNotFoundException | NotFoundException e) {
        // Could not find the icon. loadIcon call below will return the default app icon.
    }
    return info.loadIcon(mManager);
}
 
Example #26
Source File: LoadedPlugin.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable getActivityIcon(Intent intent) throws NameNotFoundException {
    ResolveInfo ri = mPluginManager.resolveActivity(intent);
    if (null != ri) {
        LoadedPlugin plugin = mPluginManager.getLoadedPlugin(ri.resolvePackageName);
        return plugin.mResources.getDrawable(ri.activityInfo.icon);
    }

    return this.mHostPackageManager.getActivityIcon(intent);
}
 
Example #27
Source File: IsServiceAvailableTest.java    From android-easy-checkout with Apache License 2.0 5 votes vote down vote up
@Test
public void isNotServiceAvailableListEmpty() throws InterruptedException, RemoteException {
    Intent serviceIntent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
    serviceIntent.setPackage(Constants.VENDING_PACKAGE);

    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);

    when(context.getPackageManager()).thenReturn(packageManager);
    when(packageManager.queryIntentServices(any(Intent.class), eq(0))).thenReturn(Collections.<ResolveInfo>emptyList());

    assertThat(BillingProcessorObservable.isServiceAvailable(context)).isFalse();
}
 
Example #28
Source File: EnabledComponentsObserver.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static ArraySet<ComponentName> loadComponentNames(PackageManager pm, int userId,
        String serviceName, String permissionName) {

    ArraySet<ComponentName> installed = new ArraySet<>();
    Intent queryIntent = new Intent(serviceName);
    List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
            queryIntent,
            PackageManager.GET_SERVICES | PackageManager.GET_META_DATA |
                                PackageManager.MATCH_DIRECT_BOOT_AWARE |
                                PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
            userId);
    if (installedServices != null) {
        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
            ServiceInfo info = resolveInfo.serviceInfo;

            ComponentName component = new ComponentName(info.packageName, info.name);
            if (!permissionName.equals(info.permission)) {
                Slog.w(TAG, "Skipping service " + info.packageName + "/" + info.name
                        + ": it does not require the permission "
                        + permissionName);
                continue;
            }
            installed.add(component);
        }
    }
    return installed;
}
 
Example #29
Source File: Tools.java    From android-tv-launcher with MIT License 5 votes vote down vote up
public static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    mainIntent.setPackage(packageName);
    final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
    return apps != null ? apps : new ArrayList<ResolveInfo>();
}
 
Example #30
Source File: TwaProviderPickerTest.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
private void installTrustedWebActivityProvider(String packageName) {
    installBrowser(packageName);

    Intent intent = new Intent()
            .setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);

    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.serviceInfo = new ServiceInfo();
    resolveInfo.serviceInfo.packageName = packageName;
    resolveInfo.filter = Mockito.mock(IntentFilter.class);
    when(resolveInfo.filter.hasCategory(eq(TRUSTED_WEB_ACTIVITY_CATEGORY))).thenReturn(true);

    mShadowPackageManager.addResolveInfoForIntent(intent, resolveInfo);
}