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.mail.ui.AbstractActivityController.java

@Override
public void executeSearch(String query) {
    AnalyticsTimer.getInstance().trackStart(AnalyticsTimer.SEARCH_TO_LIST);
    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());
    mSearchViewController.showSearchActionBar(MaterialSearchViewController.SEARCH_VIEW_STATE_GONE);
    // Call startActivityForResult here so we can tell if we have navigated to a different folder
    // or account from search results.
    mActivity.startActivityForResult(intent, CHANGE_NAVIGATION_REQUEST_CODE);
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Process a shortcut drop./*from w  ww  . j  a v a2s  .  com*/
 *
 * @param componentName The name of the component
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 */
private void processShortcutFromDrop(ComponentName componentName, long container, long screenId, int[] cell) {
    resetAddInfo();
    mPendingAddInfo.container = container;
    mPendingAddInfo.screenId = screenId;
    mPendingAddInfo.dropPos = null;

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

    Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
    createShortcutIntent.setComponent(componentName);
    Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
}

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

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///from w ww . jav  a 2  s.  c o 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:com.android.soma.Launcher.java

protected void startWallpaper() {
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    pickWallpaper.setComponent(getWallpaperPickerComponent());
    startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
}

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

/**
 * Process a shortcut drop.//from  w  ww. j  a v  a2 s .  c  o m
 *
 * @param componentName The name of the component
 * @param screenId The ID of 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, long screenId, int[] cell,
        int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = container;
    mPendingAddInfo.screenId = screenId;
    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.soma.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);
        Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
    } else {/*from  w  ww. ja v  a 2s.c  om*/
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///w w  w. jav a2  s .  co m
private 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:com.android.soma.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *//*w w w.j  ava 2  s. c o  m*/
private 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:com.cognizant.trumobi.PersonaLauncher.java

private void configureOrAddAppWidget(Intent data) {
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (appWidget.configure != null) {
        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidget.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

        startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
    } else {// w  w  w .j ava  2  s  . co  m
        // Otherwise just add it
        onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void appwidgetReadyBroadcast(int appWidgetId, ComponentName cname, int[] widgetSpan) {
    Intent motosize = new Intent("com.motorola.blur.home.ACTION_SET_WIDGET_SIZE");

    motosize.setComponent(cname);
    motosize.putExtra("appWidgetId", appWidgetId);
    motosize.putExtra("spanX", widgetSpan[0]);
    motosize.putExtra("spanY", widgetSpan[1]);
    motosize.putExtra("com.motorola.blur.home.EXTRA_NEW_WIDGET", true);
    sendBroadcast(motosize);//from   w  w w. j  a  v  a 2  s . c  o m

    Intent ready = new Intent(PersonaLauncherIntent.Action.ACTION_READY)
            .putExtra(PersonaLauncherIntent.Extra.EXTRA_APPWIDGET_ID, appWidgetId)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
            .putExtra(PersonaLauncherIntent.Extra.EXTRA_API_VERSION, PersonaLauncherMetadata.CurrentAPIVersion)
            .setComponent(cname);
    sendBroadcast(ready);
}