Example usage for android.content Intent CATEGORY_LAUNCHER

List of usage examples for android.content Intent CATEGORY_LAUNCHER

Introduction

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

Prototype

String CATEGORY_LAUNCHER

To view the source code for android.content Intent CATEGORY_LAUNCHER.

Click Source Link

Document

Should be displayed in the top-level launcher.

Usage

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 {//from  w ww.ja v  a 2s  . com
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.fairphone.fplauncher3.Workspace.java

private void updateShortcutsAndWidgetsPerUser(ArrayList<AppInfo> apps, final UserHandleCompat user) {
    // Create a map of the apps to test against
    final HashMap<ComponentName, AppInfo> appsMap = new HashMap<ComponentName, AppInfo>();
    final HashSet<String> pkgNames = new HashSet<String>();
    for (AppInfo ai : apps) {
        appsMap.put(ai.componentName, ai);
        pkgNames.add(ai.componentName.getPackageName());
    }//from   ww  w .jav  a  2  s  . c o m
    final HashSet<ComponentName> iconsToRemove = new HashSet<ComponentName>();

    mapOverItems(MAP_RECURSE, new ItemOperator() {
        @Override
        public boolean evaluate(ItemInfo info, View v, View parent) {
            if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                ComponentName cn = shortcutInfo.getTargetComponent();
                AppInfo appInfo = appsMap.get(cn);
                if (user.equals(shortcutInfo.user) && cn != null && LauncherModel.isShortcutInfoUpdateable(info)
                        && pkgNames.contains(cn.getPackageName())) {
                    boolean promiseStateChanged = false;
                    boolean infoUpdated = false;
                    if (shortcutInfo.isPromise()) {
                        if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                            // Auto install icon
                            PackageManager pm = getContext().getPackageManager();
                            ResolveInfo matched = pm
                                    .resolveActivity(
                                            new Intent(Intent.ACTION_MAIN).setComponent(cn)
                                                    .addCategory(Intent.CATEGORY_LAUNCHER),
                                            PackageManager.MATCH_DEFAULT_ONLY);
                            if (matched == null) {
                                // Try to find the best match activity.
                                Intent intent = pm.getLaunchIntentForPackage(cn.getPackageName());
                                if (intent != null) {
                                    cn = intent.getComponent();
                                    appInfo = appsMap.get(cn);
                                }

                                if ((intent == null) || (appsMap == null)) {
                                    // Could not find a default activity. Remove this item.
                                    iconsToRemove.add(shortcutInfo.getTargetComponent());

                                    // process next shortcut.
                                    return false;
                                }
                                shortcutInfo.promisedIntent = intent;
                            }
                        }

                        // Restore the shortcut.
                        shortcutInfo.intent = shortcutInfo.promisedIntent;
                        shortcutInfo.promisedIntent = null;
                        shortcutInfo.status &= ~ShortcutInfo.FLAG_RESTORED_ICON
                                & ~ShortcutInfo.FLAG_AUTOINTALL_ICON
                                & ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;

                        promiseStateChanged = true;
                        infoUpdated = true;
                        shortcutInfo.updateIcon(mIconCache);
                        LauncherModel.updateItemInDatabase(getContext(), shortcutInfo);
                    }

                    if (appInfo != null) {
                        shortcutInfo.updateIcon(mIconCache);
                        shortcutInfo.title = appInfo.title.toString();
                        shortcutInfo.contentDescription = appInfo.contentDescription;
                        infoUpdated = true;
                    }

                    if (infoUpdated) {
                        BubbleTextView shortcut = (BubbleTextView) v;
                        shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, promiseStateChanged);

                        if (parent != null) {
                            parent.invalidate();
                        }
                    }
                }
            }
            // process all the shortcuts
            return false;
        }
    });

    if (!iconsToRemove.isEmpty()) {
        removeItemsByComponentName(iconsToRemove, user);
    }
    if (user.equals(UserHandleCompat.myUserHandle())) {
        restorePendingWidgets(pkgNames);
    }
}

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

/**
 * ADW: Home binding actions//from  w  w  w .j ava  2  s. co  m
 */
public void fireHomeBinding(int bindingValue, int type) {
    // ADW: switch home button binding user selection
    if (mIsEditMode || mIsWidgetEditMode)
        return;
    switch (bindingValue) {
    case BIND_DEFAULT:
        dismissPreviews();
        if (!mWorkspace.isDefaultScreenShowing()) {
            mWorkspace.moveToDefaultScreen();
        }
        break;
    case BIND_HOME_PREVIEWS:
        if (!mWorkspace.isDefaultScreenShowing()) {
            dismissPreviews();
            mWorkspace.moveToDefaultScreen();
        } else {
            if (!showingPreviews) {
                showPreviews(mHandleView, 0, mWorkspace.mHomeScreens);
            } else {
                dismissPreviews();
            }
        }
        break;
    case BIND_PREVIEWS:
        if (!showingPreviews) {
            showPreviews(mHandleView, 0, mWorkspace.mHomeScreens);
        } else {
            dismissPreviews();
        }
        break;
    case BIND_APPS:
        dismissPreviews();
        if (isAllAppsVisible()) {
            mRAB.setVisibility(View.VISIBLE);
            mLAB.setVisibility(View.VISIBLE);
            mHandleView.updateIcon();
            closeDrawer();
        } else {
            showAllApps(true, null);

        }
        break;
    case BIND_STATUSBAR:
        WindowManager.LayoutParams attrs = getWindow().getAttributes();
        /*
         * if((attrs.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) ==
         * WindowManager.LayoutParams.FLAG_FULLSCREEN){ //go non-full screen
         * fullScreen(false); }else{ //go full screen fullScreen(true); }
         */
        // 290778 commented for Non full screen mode
        fullScreen(false);
        break;
    case BIND_NOTIFICATIONS:
        dismissPreviews();
        showNotifications();
        break;
    case BIND_HOME_NOTIFICATIONS:
        if (!mWorkspace.isDefaultScreenShowing()) {
            dismissPreviews();
            mWorkspace.moveToDefaultScreen();
        } else {
            dismissPreviews();
            showNotifications();
        }
        break;
    case BIND_DOCKBAR:
        dismissPreviews();
        if (showDockBar) {
            if (mDockBar.isOpen()) {
                mDockBar.close();
            } else {
                mDockBar.open();
            }
        }
        break;
    case BIND_APP_LAUNCHER:
        // Launch or bring to front selected app
        // Get PackageName and ClassName of selected App
        String package_name = "";
        String name = "";
        switch (type) {
        case 1:
            package_name = PersonaAlmostNexusSettingsHelper.getHomeBindingAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getHomeBindingAppToLaunchName(this);
            break;
        case 2:
            package_name = PersonaAlmostNexusSettingsHelper.getSwipeUpAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getSwipeUpAppToLaunchName(this);
            break;
        case 3:
            package_name = PersonaAlmostNexusSettingsHelper.getSwipeDownAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getSwipeDownAppToLaunchName(this);
            break;
        default:
            break;
        }
        // Create Intent to Launch App
        if (package_name != "" && name != "") {
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            i.setComponent(new ComponentName(package_name, name));
            try {
                startActivity(i);
            } catch (Exception e) {
            }
        }
        break;
    default:
        break;
    }
}