Example usage for android.content Intent getComponent

List of usage examples for android.content Intent getComponent

Introduction

In this page you can find the example usage for android.content Intent getComponent.

Prototype

public @Nullable ComponentName getComponent() 

Source Link

Document

Retrieve the concrete component associated with the intent.

Usage

From source file:com.hellofyc.base.app.AppSupportDelegate.java

public void startFragmentForResult(@NonNull Intent intent, int requestCode, @Nullable Bundle options) {
    ComponentName componentName = intent.getComponent();
    String targetFragmentClassName = componentName.getClassName();
    intent.setComponent(//from   w  ww  .ja  va  2 s.c om
            new ComponentName(componentName.getPackageName(), SingleFragmentActivity.class.getName()));
    intent.putExtra(SingleFragmentActivity.EXTRA_FRAGMENT_CLASSNAME, targetFragmentClassName);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mActivity.startActivityForResult(intent, requestCode, options);
    } else {
        mActivity.startActivityForResult(intent, requestCode);
    }
}

From source file:org.ohmage.auth.AuthenticatorTest.java

private void verifyNotifyUserBundle(Bundle bundle) {
    Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
    assertNotNull(intent);/* ww w  .  j  av  a2  s.c  o  m*/
    assertEquals(intent.getComponent().getClassName(), AuthenticatorActivity.class.getName());
    assertTrue(intent.getBooleanExtra(AuthenticatorActivity.EXTRA_FROM_AUTHENTICATOR, false));
}

From source file:edu.umich.oasis.sandbox.SandboxContext.java

@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    ComponentName component = service.getComponent();
    if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID)
            && component.getClassName().equals(OASISService.class.getName())) {
        IBinder rootBinder = mRootService.asBinder();
        ComponentName oldMapping;//  w  ww.  j  a  va2  s  .com
        synchronized (mBoundServices) {
            oldMapping = mBoundServices.put(conn, component);
        }
        if (oldMapping == null) {
            conn.onServiceConnected(component, rootBinder);
        }
        return true;
    }
    return super.bindService(service, conn, flags);
}

From source file:org.ohmage.auth.AuthenticatorTest.java

public void testGetAuthToken_userRecoverableErrorWhenAuthtokenFromGoogle_sendsErrorViaIntent()
        throws Exception {
    setAuthTokenCached(false);// www.  jav  a  2s .c o m
    setAccountRefreshToken();
    setAccessTokenFailure(refreshToken, new AuthenticationException(""));
    setHasGoogleAccount(true);
    UserRecoverableAuthException fakeException = new UserRecoverableAuthException("msg", new Intent());
    setGetGoogleAuthTokenResult(fakeException);

    Bundle data = mAuthenticator.getAuthToken(null, fakeAccount, AuthUtil.AUTHTOKEN_TYPE, null);

    Intent intent = data.getParcelable(AccountManager.KEY_INTENT);
    assertNotNull(intent);
    assertEquals(intent.getComponent().getClassName(), AuthenticatorActivity.class.getName());
    assertEquals(fakeException,
            intent.getSerializableExtra(AuthenticatorActivity.EXTRA_HANDLE_USER_RECOVERABLE_ERROR));
}

From source file:mobisocial.musubi.ui.FeedIdentityGrid.java

String getCallerAppId() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<RecentTaskInfo> infos = manager.getRecentTasks(1, 0);
    if (infos.size() == 0) {
        Log.w(TAG, "couldn't get info");
        return null;
    }/*w  w  w  . java2  s. c  o  m*/

    Intent base = infos.get(0).baseIntent;
    return base.getComponent().getPackageName();
}

From source file:com.android.settings.security.SecurityFeatureProviderImpl.java

@VisibleForTesting
void updatePreferencesToRunOnWorkerThread(Context context, PreferenceScreen preferenceScreen,
        DashboardCategory dashboardCategory) {

    int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
    Map<String, IContentProvider> providerMap = new ArrayMap<>();
    for (int i = 0; i < tilesCount; i++) {
        Tile tile = dashboardCategory.getTile(i);
        // If the tile does not have a key or appropriate meta data, skip it.
        if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
            continue;
        }/*w w  w .j ava  2s. c o  m*/
        Preference matchingPref = preferenceScreen.findPreference(tile.key);
        // If the tile does not have a matching preference, skip it.
        if (matchingPref == null) {
            continue;
        }
        // Check if the tile has content providers for dynamically updatable content.
        final String iconUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_ICON_URI, null);
        final String summaryUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
        if (!TextUtils.isEmpty(iconUri)) {
            String packageName = null;
            if (tile.intent != null) {
                Intent intent = tile.intent;
                if (!TextUtils.isEmpty(intent.getPackage())) {
                    packageName = intent.getPackage();
                } else if (intent.getComponent() != null) {
                    packageName = intent.getComponent().getPackageName();
                }
            }
            Pair<String, Integer> icon = TileUtils.getIconFromUri(context, packageName, iconUri, providerMap);
            if (icon != null) {
                sIconCache.put(iconUri, icon);
                // Icon is only returned if the icon belongs to Settings or the target app.
                // setIcon must be called on the UI thread.
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            matchingPref.setIcon(context.getPackageManager()
                                    .getResourcesForApplication(icon.first /* package name */)
                                    .getDrawable(icon.second /* res id */, context.getTheme()));
                        } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
                            // Intentionally ignored. If icon resources cannot be found, do not
                            // update.
                        }
                    }
                });
            }
        }
        if (!TextUtils.isEmpty(summaryUri)) {
            String summary = TileUtils.getTextFromUri(context, summaryUri, providerMap,
                    TileUtils.META_DATA_PREFERENCE_SUMMARY);
            sSummaryCache.put(summaryUri, summary);
            // setSummary must be called on UI thread.
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    // Only update the summary if it has actually changed.
                    if (summary == null) {
                        if (matchingPref.getSummary() != null) {
                            matchingPref.setSummary(summary);
                        }
                    } else if (!summary.equals(matchingPref.getSummary())) {
                        matchingPref.setSummary(summary);
                    }
                }
            });
        }
    }
}

From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java

/**
 * Add a new Intent with the resolved chain of parents for the target
 * activity to the task stack./*from  w  w w.  j  a v a2s. c  o  m*/
 * 
 * <p>
 * This is equivalent to calling {@link #addParentStack(ComponentName)
 * addParentStack} with the resolved ComponentName of nextIntent (if it can
 * be resolved), followed by {@link #addNextIntent(Intent) addNextIntent}
 * with nextIntent.
 * </p>
 * 
 * @param nextIntent
 *            Intent for the topmost Activity in the synthesized task stack.
 *            Its chain of parents as specified in the manifest will be
 *            added.
 * @return This DualTaskStackBuilder for method chaining.
 */
public DualTaskStackBuilder addNextIntentWithParentStack(Intent nextIntent) {
    ComponentName target = nextIntent.getComponent();
    if (target == null) {
        target = nextIntent.resolveActivity(mSourceContext.getPackageManager());
    }
    if (target != null) {
        addParentStack(target);
    }
    addNextIntent(nextIntent);
    return this;
}

From source file:edu.umich.flowfence.sandbox.SandboxContext.java

@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    ComponentName component = service.getComponent();
    if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID)
            && component.getClassName().equals(FlowfenceService.class.getName())) {
        IBinder rootBinder = mRootService.asBinder();
        ComponentName oldMapping;/*from  w  w w  .jav  a  2 s .  c o  m*/
        synchronized (mBoundServices) {
            oldMapping = mBoundServices.put(conn, component);
        }
        if (oldMapping == null) {
            conn.onServiceConnected(component, rootBinder);
        }
        return true;
    }
    return super.bindService(service, conn, flags);
}

From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java

private boolean isTopLevelTile(Intent intent) {
    final ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        return false;
    }//www .  j ava  2  s.  c  o  m
    // Look for a tile that has the same component as incoming intent
    final List<DashboardCategory> categories = getDashboardCategories();
    for (DashboardCategory category : categories) {
        for (Tile tile : category.tiles) {
            if (TextUtils.equals(tile.intent.getComponent().getClassName(), componentName.getClassName())) {
                if (DEBUG) {
                    Log.d(TAG, "intent is for top level tile: " + tile.title);
                }
                return true;
            }
        }
    }
    if (DEBUG) {
        Log.d(TAG, "Intent is not for top level settings " + intent);
    }
    return false;
}

From source file:com.apptentive.android.sdk.ApptentiveViewActivity.java

private void startLauncherActivityIfRoot() {
    if (isTaskRoot()) {
        PackageManager packageManager = getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(getPackageName());
        ComponentName componentName = intent.getComponent();
        /** Backwards compatible method that will clear all activities in the stack. */
        Intent mainIntent = IntentCompat.makeRestartActivityTask(componentName);
        startActivity(mainIntent);//from ww w  . ja va 2  s  . c  om
    }
}