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:Main.java

public static void toHome(Context context) {
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addCategory(Intent.CATEGORY_HOME);
    context.startActivity(i);/*  w w w  . j a va2  s .c  o  m*/
}

From source file:Main.java

public static boolean backToHome(Context c) {
    Intent i = new Intent(Intent.ACTION_MAIN);

    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addCategory(Intent.CATEGORY_HOME);

    c.startActivity(i);//from  www  .java  2  s  .  c om

    return true;
}

From source file:Main.java

public static void imitateHome(Context context) {
    try {//from w w w.j  a  v a 2s.c  o  m
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_HOME);
        context.startActivity(intent);
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:Main.java

public static String getLauncherPackageName(Context context) {
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
    return res.activityInfo.packageName;
}

From source file:Main.java

public static void gotoDeskTop(AccessibilityService service) {
    try {/*ww  w  .j av a  2 s  . c o m*/
        Intent home = new Intent(Intent.ACTION_MAIN);
        home.addCategory(Intent.CATEGORY_HOME);
        home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        service.getApplicationContext().startActivity(home);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * start home intent//from w  w w  .ja va 2s. c  om
 *
 * @param context
 */
public static void startHomeActivity(Context context) {
    Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(homeIntent);
}

From source file:Main.java

/**
 * Minimizes the app/*  w  w w  .j a  va  2  s. c  o  m*/
 * @param context the context
 */
public static void minimizeApp(Context context) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startMain);
}

From source file:Main.java

/**
 * "Exits" the app to the Home screen".//from  w  w w  .j  a  v  a2s.  co m
 * @param context Application context
 */
public static void exitToHome(final Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

@NonNull
private static String getDefaultLauncher(@NonNull Context context) {
    final Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo.activityInfo.packageName;
}

From source file:Main.java

public static boolean isMyLauncherDefault(Context context) {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);/*  w w  w . j  a va 2s .com*/

    final String myPackageName = context.getPackageName();
    List<ComponentName> activities = new ArrayList<>();
    PackageManager packageManager = (PackageManager) context.getPackageManager();

    // You can use name of your package here as third argument
    packageManager.getPreferredActivities(filters, activities, null);

    if (activities.size() == 0) //no default
        return true;

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }
    return false;
}