Example usage for android.content Intent CATEGORY_HOME

List of usage examples for android.content Intent CATEGORY_HOME

Introduction

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

Prototype

String CATEGORY_HOME

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

Click Source Link

Document

This is the home activity, that is the first activity that is displayed when the device boots.

Usage

From source file:com.farmerbb.secondscreen.util.U.java

public static String uiRefreshCommand2(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    // For better reliability, we execute the UI refresh while on the home screen
    Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(homeIntent);/*w w w  .j av a  2 s  . c om*/

    // Kill all background processes, in order to fully refresh UI
    PackageManager pm = context.getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if (!packageInfo.packageName.equalsIgnoreCase(context.getPackageName()))
            am.killBackgroundProcesses(packageInfo.packageName);
    }

    // Get launcher package name
    final ResolveInfo mInfo = pm.resolveActivity(homeIntent, 0);

    return "sleep 1 && am force-stop " + mInfo.activityInfo.applicationInfo.packageName;
}

From source file:edu.chalmers.dat255.audiobookplayer.view.MainActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();

    Log.i(TAG, "Back pressed in Main Activity");
    Intent intent = new Intent(Intent.ACTION_MAIN);

    // move to the home screen when pressing back
    intent.addCategory(Intent.CATEGORY_HOME);

    // start a new task
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from www.  jav  a  2 s.com*/
}

From source file:org.noise_planet.noisecapture.MainActivity.java

@Override
public void onBackPressed() {
    if (!(this instanceof MeasurementActivity)) {
        if (mDrawerLayout != null) {
            mDrawerLayout.closeDrawer(mDrawerList);
        }/*w  ww  .  java 2s  . c  om*/
        Intent im = new Intent(getApplicationContext(), MeasurementActivity.class);
        im.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(im);
        finish();
    } else {
        finish();
        // Show home
        Intent im = new Intent(Intent.ACTION_MAIN);
        im.addCategory(Intent.CATEGORY_HOME);
        im.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(im);
    }
}

From source file:io.selendroid.server.ServerInstrumentation.java

public void backgroundActivity() {
    activitiesReporter.setBackgroundActivity(activitiesReporter.getCurrentActivity());
    Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getTargetContext().startActivity(homeIntent);
}

From source file:org.wso2.mdm.agent.AlreadyRegisteredActivity.java

/**
 * Load device home screen./*from w  w w. j ava 2 s.  c om*/
 */

private void loadHomeScreen() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    super.onBackPressed();
}

From source file:wanthavers.mad.cs.fau.de.wanthavers_android.desirelist.DesireListActivity.java

@Override
public void onBackPressed() {

    if (backButtonCount < 1) {
        mDrawerLayout.closeDrawers();//  w  w  w. j  ava  2  s.  c o  m
    }
    if (backButtonCount >= 1) {
        backButtonCount = 0;
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        Toast.makeText(this, getString(R.string.close_App_on_BackButton), Toast.LENGTH_SHORT).show();
        backButtonCount++;
    }
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
private void generateMenu() {
    if (isStartButton) {
        addPreferencesFromResource(R.xml.pref_context_menu_open_settings);
        findPreference("open_taskbar_settings").setOnPreferenceClickListener(this);
        findPreference("start_menu_apps").setOnPreferenceClickListener(this);

        if (U.launcherIsDefault(this) && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
            addPreferencesFromResource(R.xml.pref_context_menu_change_wallpaper);
            findPreference("change_wallpaper").setOnPreferenceClickListener(this);
        }/*from   w  w w . j  av  a  2s. c om*/

        if (!getIntent().getBooleanExtra("dont_show_quit", false)) {
            addPreferencesFromResource(R.xml.pref_context_menu_quit);
            findPreference("quit_taskbar").setOnPreferenceClickListener(this);
        }
    } else if (isOverflowMenu) {
        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(R.string.tools);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(R.string.tools);
        }

        addPreferencesFromResource(R.xml.pref_context_menu_overflow);
        findPreference("volume").setOnPreferenceClickListener(this);
        findPreference("system_settings").setOnPreferenceClickListener(this);
        findPreference("lock_device").setOnPreferenceClickListener(this);
        findPreference("power_menu").setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            findPreference("file_manager").setOnPreferenceClickListener(this);
        else
            getPreferenceScreen().removePreference(findPreference("file_manager"));
    } else {
        appName = getIntent().getStringExtra("app_name");
        packageName = getIntent().getStringExtra("package_name");
        componentName = getIntent().getStringExtra("component_name");
        userId = getIntent().getLongExtra("user_id", 0);

        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(appName);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(appName);
        }

        SharedPreferences pref = U.getSharedPreferences(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                && !U.isGame(this, packageName)) {
            addPreferencesFromResource(R.xml.pref_context_menu_show_window_sizes);
            findPreference("show_window_sizes").setOnPreferenceClickListener(this);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            int shortcutCount = getLauncherShortcuts();

            if (shortcutCount > 1) {
                addPreferencesFromResource(R.xml.pref_context_menu_shortcuts);
                findPreference("app_shortcuts").setOnPreferenceClickListener(this);
            } else if (shortcutCount == 1)
                generateShortcuts();
        }

        final PackageManager pm = getPackageManager();
        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
        homeIntent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo defaultLauncher = pm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);

        if (!packageName.contains(BuildConfig.BASE_APPLICATION_ID)
                && !packageName.equals(defaultLauncher.activityInfo.packageName)) {
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);

            if (pba.isPinned(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_pin);
                findPreference("pin_app").setOnPreferenceClickListener(this);
                findPreference("pin_app").setTitle(R.string.unpin_app);
            } else if (pba.isBlocked(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.unblock_app);
            } else {
                final int MAX_NUM_OF_COLUMNS = U.getMaxNumOfEntries(this);

                if (pba.getPinnedApps().size() < MAX_NUM_OF_COLUMNS) {
                    addPreferencesFromResource(R.xml.pref_context_menu_pin);
                    findPreference("pin_app").setOnPreferenceClickListener(this);
                    findPreference("pin_app").setTitle(R.string.pin_app);
                }

                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.block_app);
            }
        }

        addPreferencesFromResource(R.xml.pref_context_menu);

        findPreference("app_info").setOnPreferenceClickListener(this);
        findPreference("uninstall").setOnPreferenceClickListener(this);
    }
}

From source file:com.spydiko.rotationmanager.MainActivity.java

public void updateApps() {
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "0");
    Intent localIntent = new Intent("android.intent.action.MAIN", null);
    localIntent.addCategory("android.intent.category.LAUNCHER");
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "1");
    packageManager = getPackageManager();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "2");
    List<ResolveInfo> rInfo = packageManager.queryIntentActivities(localIntent, 1);
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "3");
    List<ApplicationInfo> packages = new ArrayList<ApplicationInfo>();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "4");
    for (ResolveInfo info : rInfo) {
        packages.add(info.activityInfo.applicationInfo);
    }//from  w w w .j  a v a2  s  .  co m
    Model temp;
    for (ApplicationInfo packageInfo : packages) {
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + packageInfo.packageName);
        if (names.contains(packageInfo.packageName)) {
            continue;
        }
        names.add(packageInfo.packageName);
        temp = new Model((String) packageManager.getApplicationLabel(packageInfo));
        temp.setPackageName(packageInfo.packageName);
        Drawable pic = packageInfo.loadIcon(packageManager);
        temp.setLabel(pic);
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + temp.getName());
        //temp.put(IS_CHECKED, true);
        if (myapp.loadPreferences(packageInfo.packageName, true))
            temp.setSelectedPortrait(true);
        if (myapp.loadPreferences(packageInfo.packageName, false))
            temp.setSelectedLandscape(true);
        activities.add(temp);

        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Launch Activity :" + packageManager.getLaunchIntentForPackage(packageInfo.packageName));
    }
    // Search and show launchers
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = packageManager.resolveActivity(intent, 0);
    if (res.activityInfo == null) {
        // should not happen. A home is always installed, isn't it?
    } else if (!names.contains(res.activityInfo.applicationInfo.packageName)) {
        names.add(res.activityInfo.applicationInfo.packageName);
        Model launcher = new Model(
                (String) packageManager.getApplicationLabel(res.activityInfo.applicationInfo));
        launcher.setPackageName(res.activityInfo.applicationInfo.packageName);
        Drawable launcher_pic = res.activityInfo.applicationInfo.loadIcon(packageManager);
        launcher.setLabel(launcher_pic);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, true))
            launcher.setSelectedPortrait(true);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, false))
            launcher.setSelectedLandscape(true);
        activities.add(launcher);
    }
    if (!names.contains("com.android.phone")) {
        names.add("com.android.phone");
        Model phone = new Model("Phone During Call");
        phone.setPackageName("com.android.phone");
        Drawable ic_phone = getResources().getDrawable(R.drawable.ic_phone);
        phone.setLabel(ic_phone);
        if (myapp.loadPreferences("com.android.phone", true))
            phone.setSelectedPortrait(true);
        if (myapp.loadPreferences("com.android.phone", false))
            phone.setSelectedLandscape(true);
        activities.add(phone);
    }

    Collections.sort(activities, new SortByString());

    Collections.sort(activities, new SortByCheck());

    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "END");
}

From source file:com.nordicsemi.UART_UDP_PROXY.MainActivity.java

@Override
public void onBackPressed() {
    if (mState == UART_PROFILE_CONNECTED) {
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);//  w  w w . j av  a 2 s  .  co m
        showMessage("UART-UDP Proxy running in background.\n             Disconnect to exit");
    } else {
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.popup_title)
                .setMessage(R.string.popup_message)
                .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.popup_no, null).show();
    }
}

From source file:com.quickcar.thuexe.UI.ListPassengerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        if (doubleBackToExitPressedOnce) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);/*w w  w .  j  av  a 2 s.c  o  m*/
        } else {
            Toast.makeText(mContext, getResources().getString(R.string.notice_close_app), Toast.LENGTH_SHORT)
                    .show();
            this.doubleBackToExitPressedOnce = true;
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    doubleBackToExitPressedOnce = false;
                }
            }, 2000);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 1) {
        finish();
    }

    return super.onKeyDown(keyCode, event);
}