@Override public ResolveInfo resolveActivity(Intent intent, int flags) { return mBase.resolveActivity(intent, flags); }
private static boolean isIntentResolvable(Context context, Intent intent) { return context.getPackageManager().resolveActivity(intent, 0) != null; } }
private boolean resolveIntent(Intent intent) { ResolveInfo resolveInfo = FacebookSdk.getApplicationContext().getPackageManager() .resolveActivity(intent, 0); return resolveInfo != null; }
public static boolean hasEffectsPanel(final Activity activity) { final PackageManager packageManager = activity.getPackageManager(); return packageManager.resolveActivity(createEffectsIntent(), PackageManager.MATCH_DEFAULT_ONLY) != null; }
@Override public boolean openURI (String URI) { boolean result = false; final Uri uri = Uri.parse(URI); Intent intent = new Intent(Intent.ACTION_VIEW, uri); PackageManager pm = app.getContext().getPackageManager(); if (pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) { app.runOnUiThread(new Runnable() { @Override public void run () { Intent intent = new Intent(Intent.ACTION_VIEW, uri); // LiveWallpaper and Daydream applications need this flag if (!(app.getContext() instanceof Activity)) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); app.startActivity(intent); } }); result = true; } return result; }
@Override public boolean openURI (String URI) { boolean result = false; final Uri uri = Uri.parse(URI); Intent intent = new Intent(Intent.ACTION_VIEW, uri); PackageManager pm = app.getContext().getPackageManager(); if (pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) { app.runOnUiThread(new Runnable() { @Override public void run () { Intent intent = new Intent(Intent.ACTION_VIEW, uri); // LiveWallpaper and Daydream applications need this flag if (!(app.getContext() instanceof Activity)) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); app.startActivity(intent); } }); result = true; } return result; }
static Intent validateActivityIntent(Context context, Intent intent, NativeAppInfo appInfo) { if (intent == null) { return null; } ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, 0); if (resolveInfo == null) { return null; } if (!FacebookSignatureValidator.validateSignature( context, resolveInfo.activityInfo.packageName)) { return null; } return intent; }
private void verifyActivityInManifest(Intent intent) { if (checkActivities && RuntimeEnvironment.application .getPackageManager() .resolveActivity(intent, MATCH_DEFAULT_ONLY) == null) { throw new ActivityNotFoundException(intent.getAction()); } }
/** * Ensure that an Activity is available to receive the given Intent */ public static boolean activityExists (Context ctx, Intent intent) { final PackageManager mgr = ctx.getPackageManager(); final ResolveInfo info = mgr.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY); return (info != null); } public static void showAdvancedWifiIfAvailable (Context ctx) { final Intent i = new Intent(Settings.ACTION_WIFI_IP_SETTINGS); if (activityExists(ctx, i)) { ctx.startActivity(i); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PackageManager mgr=getPackageManager(); Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse("https://commonsware.com")); ResolveInfo ri= mgr.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY); Toast.makeText(this, ri.loadLabel(mgr), Toast.LENGTH_LONG).show(); startActivity(i); finish(); } }
@Override public Intent getIntentForActivity(Class<? extends Activity> activityClass) { Intent intent = Intent.makeMainActivity(new ComponentName(getTargetContext(), activityClass)); if (getTargetContext().getPackageManager().resolveActivity(intent, 0) != null) { return intent; } return Intent.makeMainActivity(new ComponentName(getContext(), activityClass)); } }
public VPackageManagerService() { Intent intent = new Intent(); intent.setClassName(VirtualCore.get().getHostPkg(), VASettings.RESOLVER_ACTIVITY); mResolveInfo = VirtualCore.get().getUnHookPackageManager().resolveActivity(intent, 0); }
@Test public void resolveActivity_NoMatch() throws Exception { Intent i = new Intent(); i.setComponent(new ComponentName("foo.bar", "No Activity")); assertThat(packageManager.resolveActivity(i, 0)).isNull(); }
/** * Uses package manager to find the package name of the device launcher. Usually this package * is "com.android.launcher" but can be different at times. This is a generic solution which * works on all platforms.` */ private String getLauncherPackageName() { // Create launcher Intent final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); // Use PackageManager to get the launcher package name PackageManager pm = getApplicationContext().getPackageManager(); ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo.activityInfo.packageName; } }
@Test public void resolveActivity_Match() throws Exception { Intent i = new Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER); ResolveInfo info = new ResolveInfo(); info.nonLocalizedLabel = TEST_PACKAGE_LABEL; info.activityInfo = new ActivityInfo(); info.activityInfo.name = "name"; info.activityInfo.packageName = TEST_PACKAGE_NAME; shadowPackageManager.addResolveInfoForIntent(i, info); assertThat(packageManager.resolveActivity(i, 0)).isNotNull(); assertThat(packageManager.resolveActivity(i, 0).activityInfo.name).isEqualTo("name"); assertThat(packageManager.resolveActivity(i, 0).activityInfo.packageName) .isEqualTo(TEST_PACKAGE_NAME); }
@Test public void testLogInThrowsIfCannotResolveFacebookActivity() { when(mockPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(null); LoginManager loginManager = new LoginManager(); try { loginManager.logInWithReadPermissions(mockActivity, Arrays.asList("public_profile", "user_friends")); fail(); } catch(FacebookException exception) { } }
@Test public void testResolveDifferentIntentObjects() { Intent intent1 = new Intent(Intent.ACTION_MAIN); intent1.setPackage(TEST_PACKAGE_LABEL); intent1.addCategory(Intent.CATEGORY_APP_BROWSER); assertThat(packageManager.resolveActivity(intent1, 0)).isNull(); ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.activityInfo = new ActivityInfo(); resolveInfo.activityInfo.packageName = TEST_PACKAGE_LABEL; resolveInfo.activityInfo.name = "BrowserActivity"; shadowPackageManager.addResolveInfoForIntent(intent1, resolveInfo); // the original intent object should yield a result ResolveInfo result = packageManager.resolveActivity(intent1, 0); assertThat(result.activityInfo.name).isEqualTo("BrowserActivity"); // AND a new, functionally equivalent intent should also yield a result Intent intent2 = new Intent(Intent.ACTION_MAIN); intent2.setPackage(TEST_PACKAGE_LABEL); intent2.addCategory(Intent.CATEGORY_APP_BROWSER); result = packageManager.resolveActivity(intent2, 0); assertThat(result.activityInfo.name).isEqualTo("BrowserActivity"); }
@Test public void removeResolveInfosForIntent_shouldCauseResolveActivityToReturnNull() throws Exception { Intent intent = new Intent(Intent.ACTION_APP_ERROR, null).addCategory(Intent.CATEGORY_APP_BROWSER); ResolveInfo info = new ResolveInfo(); info.nonLocalizedLabel = TEST_PACKAGE_LABEL; info.activityInfo = new ActivityInfo(); info.activityInfo.packageName = "com.org"; shadowPackageManager.addResolveInfoForIntent(intent, info); shadowPackageManager.removeResolveInfosForIntent(intent, "com.org"); assertThat(packageManager.resolveActivity(intent, 0)).isNull(); }
private void processActivityIntent(Intent intent) { String origPackageName = null; String origClassName = null; if (intent.getComponent() != null) { origPackageName = intent.getComponent().getPackageName(); origClassName = intent.getComponent().getClassName(); } else { ResolveInfo rInfo = mContext.getPackageManager().resolveActivity(intent, 0); if (rInfo == null) { rInfo = IncrementComponentManager.resolveIntent(intent); } if (rInfo != null && rInfo.filter != null && rInfo.filter.hasCategory(Intent.CATEGORY_DEFAULT)) { origPackageName = rInfo.activityInfo.packageName; origClassName = rInfo.activityInfo.name; } } if (IncrementComponentManager.isIncrementActivity(origClassName)) { final ActivityInfo origInfo = IncrementComponentManager.queryActivityInfo(origClassName); final boolean isTransparent = hasTransparentTheme(origInfo); final String stubClassName = ActivityStubManager.assignStub(origClassName, origInfo.launchMode, isTransparent); storeAndReplaceOriginalComponentName(intent, origPackageName, origClassName, stubClassName); } }
@Test public void resolveActivity_preferred() { ComponentName preferredName = new ComponentName("preferred", "LauncherActivity"); ComponentName otherName = new ComponentName("other", "LauncherActivity"); Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); shadowPackageManager.setResolveInfosForIntent( homeIntent, ImmutableList.of( ShadowResolveInfo.newResolveInfo( "label1", otherName.getPackageName(), otherName.getClassName()), ShadowResolveInfo.newResolveInfo( "label2", preferredName.getPackageName(), preferredName.getClassName()))); ResolveInfo resolveInfo = packageManager.resolveActivity(homeIntent, 0); assertThat(resolveInfo.activityInfo.packageName).isEqualTo(otherName.getPackageName()); // Setup an intentfilter and add to packagemanager IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); packageManager.addPreferredActivity(filter, 0, null, preferredName); resolveInfo = packageManager.resolveActivity(homeIntent, 0); assertThat(resolveInfo.activityInfo.packageName).isEqualTo(preferredName.getPackageName()); }