Example usage for android.content Intent setComponent

List of usage examples for android.content Intent setComponent

Introduction

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

Prototype

public @NonNull Intent setComponent(@Nullable ComponentName component) 

Source Link

Document

(Usually optional) Explicitly set the component to handle the intent.

Usage

From source file:com.android.tv.MainActivity.java

/**
 * Starts setup activity for the given input {@code input}.
 *
 * @param calledByPopup If true, startSetupActivity is invoked from the setup fragment.
 *//* w w w.  j a v a2s.co  m*/
public void startSetupActivity(TvInputInfo input, boolean calledByPopup) {
    Intent intent = TvCommonUtils.createSetupIntent(input);
    if (intent == null) {
        Toast.makeText(this, R.string.msg_no_setup_activity, Toast.LENGTH_SHORT).show();
        return;
    }
    // Even though other app can handle the intent, the setup launched by Live channels
    // should go through Live channels SetupPassthroughActivity.
    intent.setComponent(new ComponentName(this, SetupPassthroughActivity.class));
    try {
        // Now we know that the user intends to set up this input. Grant permission for writing
        // EPG data.
        SetupUtils.grantEpgPermission(this, input.getServiceInfo().packageName);

        mInputIdUnderSetup = input.getId();
        mIsSetupActivityCalledByPopup = calledByPopup;
        // Call requestVisibleBehind(false) before starting other activity.
        // In Activity.requestVisibleBehind(false), this activity is scheduled to be stopped
        // immediately if other activity is about to start. And this activity is scheduled to
        // to be stopped again after onPause().
        stopTv("startSetupActivity()", false);
        startActivityForResult(intent, REQUEST_CODE_START_SETUP_ACTIVITY);
    } catch (ActivityNotFoundException e) {
        mInputIdUnderSetup = null;
        Toast.makeText(this, getString(R.string.msg_unable_to_start_setup_activity, input.loadLabel(this)),
                Toast.LENGTH_SHORT).show();
        return;
    }
    if (calledByPopup) {
        mOverlayManager.hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_WITHOUT_ANIMATION
                | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_FRAGMENT);
    } else {
        mOverlayManager.hideOverlays(TvOverlayManager.FLAG_HIDE_OVERLAYS_WITHOUT_ANIMATION
                | TvOverlayManager.FLAG_HIDE_OVERLAYS_KEEP_SIDE_PANEL_HISTORY);
    }
}

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

private final PendingIntent retrievePlaybackAction(final String action) {
    final ComponentName serviceName = new ComponentName(this, MusicPlaybackService.class);
    Intent intent = new Intent(action);
    intent.setComponent(serviceName);

    return PendingIntent.getService(this, 0, intent, 0);
}

From source file:org.mdc.chess.MDChess.java

private void selectScidFile() {
    setAutoMode(AutoMode.OFF);/*from  ww  w . j av a2s  . com*/
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("org.scid.android", "org.scid.android.SelectFileActivity"));
    intent.setAction(".si4");
    try {
        startActivityForResult(intent, RESULT_SELECT_SCID);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.android.launcher2.Launcher.java

/**
 * Process a shortcut drop.//from www. jav a  2  s . co  m
 *
 * @param componentName The name of the component
 * @param screen The screen where it should be added
 * @param cell The cell it should be added to, optional
 * @param position The location on the screen where it was dropped, optional
 */
void processShortcutFromDrop(ComponentName componentName, long container, int screen, int[] cell, int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = container;
    mPendingAddInfo.screen = screen;
    mPendingAddInfo.dropPos = loc;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }

    Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
    createShortcutIntent.setComponent(componentName);
    processShortcut(createShortcutIntent);
}

From source file:com.android.launcher2.Launcher.java

void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
        AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
    } else {//from w  w  w .j  a  v a  2 s . c  om
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}

From source file:com.android.launcher2.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 */// ww  w .  java 2 s . co m
public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search, if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:org.petero.droidfish.DroidFish.java

private final void selectScidFile() {
    setAutoMode(AutoMode.OFF);/*from www .ja  va  2s  .  c  o m*/
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("org.scid.android", "org.scid.android.SelectFileActivity"));
    intent.setAction(".si4");
    try {
        startActivityForResult(intent, RESULT_SELECT_SCID);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.example.sensingapp.SensingApp.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //Show MAIN app without finishing current activity
        ActivityInfo ai = m_riHome.activityInfo;
        Intent startIntent = new Intent(Intent.ACTION_MAIN);
        startIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        startIntent.setComponent(new ComponentName(ai.packageName, ai.name));
        startActivitySafely(startIntent);
        return true;
    } else {/*w w w.  jav a  2s  . c om*/
        return super.onKeyDown(keyCode, event);
    }
}

From source file:edu.mit.viral.shen.DroidFish.java

private final void selectScidFile() {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("org.scid.android", "org.scid.android.SelectFileActivity"));
    intent.setAction(".si4");
    try {/*from   w w  w.ja v a  2  s.co  m*/
        startActivityForResult(intent, RESULT_SELECT_SCID);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.chen.mail.ui.AbstractActivityController.java

@Override
public void executeSearch(String query) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(ConversationListContext.EXTRA_SEARCH_QUERY, query);
    intent.putExtra(Utils.EXTRA_ACCOUNT, mAccount);
    intent.setComponent(mActivity.getComponentName());
    mActionBarView.collapseSearch();/*w ww.  j a v a2  s.c om*/
    mActivity.startActivity(intent);
}