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:mgks.os.webview.MainActivity.java

public boolean url_actions(WebView view, String url) {
    boolean a = true;
    //Show toast error if not connected to the network
    if (!ASWP_OFFLINE && !DetectConnection.isInternetAvailable(MainActivity.this)) {
        Toast.makeText(getApplicationContext(), getString(R.string.check_connection), Toast.LENGTH_SHORT)
                .show();/* w  w  w .  ja v a  2  s .c o m*/

        //Use this in a hyperlink to redirect back to default URL :: href="refresh:android"
    } else if (url.startsWith("refresh:")) {
        pull_fresh();

        //Use this in a hyperlink to launch default phone dialer for specific number :: href="tel:+919876543210"
    } else if (url.startsWith("tel:")) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
        startActivity(intent);

        //Use this to open your apps page on google play store app :: href="rate:android"
    } else if (url.startsWith("rate:")) {
        final String app_package = getPackageName(); //requesting app package name from Context or Activity object
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + app_package)));
        } catch (ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=" + app_package)));
        }

        //Sharing content from your webview to external apps :: href="share:URL" and remember to place the URL you want to share after share:___
    } else if (url.startsWith("share:")) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, view.getTitle());
        intent.putExtra(Intent.EXTRA_TEXT,
                view.getTitle() + "\nVisit: " + (Uri.parse(url).toString()).replace("share:", ""));
        startActivity(Intent.createChooser(intent, getString(R.string.share_w_friends)));

        //Use this in a hyperlink to exit your app :: href="exit:android"
    } else if (url.startsWith("exit:")) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

        //Getting location for offline files
    } else if (url.startsWith("offloc:")) {
        String offloc = ASWV_URL + "?loc=" + get_location();
        aswm_view(offloc, false);
        Log.d("OFFLINE LOC REQ", offloc);

        //Opening external URLs in android default web browser
    } else if (ASWP_EXTURL && !aswm_host(url).equals(ASWV_HOST)) {
        aswm_view(url, true);
    } else {
        a = false;
    }
    return a;
}

From source file:org.wso2.cdm.agent.AuthenticationActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        this.startActivity(i);
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_HOME) {
        this.finish();
        return true;
    }//w  w w.j a v a  2s  .  com
    return super.onKeyDown(keyCode, event);
}

From source file:com.nordicsemi.ImageTransferDemo.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  . ja va2  s  . c  om
        showMessage("nRFUART's running in background.\n             Disconnect to exit");
    } else {
        finish();
    }
}

From source file:root.magicword.MagicWord.java

@Override
public void onBackPressed() {

    new AlertDialog.Builder(this).setTitle("Exit").setMessage("Are you sure you want to exit this application?")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent i = new Intent();
                    i.setAction(Intent.ACTION_MAIN);
                    i.addCategory(Intent.CATEGORY_HOME);
                    MagicWord.this.startActivity(i);
                    finish();//from w w w  .  j  ava2 s  .c  o  m
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // do nothing
                }
            }).show();

}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressWarnings("Convert2streamapi")
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void updateRecentApps(final boolean firstRefresh) {
    SharedPreferences pref = U.getSharedPreferences(this);
    final PackageManager pm = getPackageManager();
    final List<AppEntry> entries = new ArrayList<>();
    List<LauncherActivityInfo> launcherAppCache = new ArrayList<>();
    int maxNumOfEntries = U.getMaxNumOfEntries(this);
    int realNumOfPinnedApps = 0;
    boolean fullLength = pref.getBoolean("full_length", false);

    PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
    List<AppEntry> pinnedApps = pba.getPinnedApps();
    List<AppEntry> blockedApps = pba.getBlockedApps();
    List<String> applicationIdsToRemove = new ArrayList<>();

    // Filter out anything on the pinned/blocked apps lists
    if (pinnedApps.size() > 0) {
        UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
        LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);

        for (AppEntry entry : pinnedApps) {
            boolean packageEnabled = launcherApps.isPackageEnabled(entry.getPackageName(),
                    userManager.getUserForSerialNumber(entry.getUserId(this)));

            if (packageEnabled)
                entries.add(entry);/* ww  w.  j  a v  a  2  s.  c o m*/
            else
                realNumOfPinnedApps--;

            applicationIdsToRemove.add(entry.getPackageName());
        }

        realNumOfPinnedApps = realNumOfPinnedApps + pinnedApps.size();
    }

    if (blockedApps.size() > 0) {
        for (AppEntry entry : blockedApps) {
            applicationIdsToRemove.add(entry.getPackageName());
        }
    }

    // Get list of all recently used apps
    List<AppEntry> usageStatsList = realNumOfPinnedApps < maxNumOfEntries ? getAppEntries() : new ArrayList<>();
    if (usageStatsList.size() > 0 || realNumOfPinnedApps > 0 || fullLength) {
        if (realNumOfPinnedApps < maxNumOfEntries) {
            List<AppEntry> usageStatsList2 = new ArrayList<>();
            List<AppEntry> usageStatsList3 = new ArrayList<>();
            List<AppEntry> usageStatsList4 = new ArrayList<>();
            List<AppEntry> usageStatsList5 = new ArrayList<>();
            List<AppEntry> usageStatsList6;

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

            // Filter out apps without a launcher intent
            // Also filter out the current launcher, and Taskbar itself
            for (AppEntry packageInfo : usageStatsList) {
                if (hasLauncherIntent(packageInfo.getPackageName())
                        && !packageInfo.getPackageName().contains(BuildConfig.BASE_APPLICATION_ID)
                        && !packageInfo.getPackageName().equals(defaultLauncher.activityInfo.packageName))
                    usageStatsList2.add(packageInfo);
            }

            // Filter out apps that don't fall within our current search interval
            for (AppEntry stats : usageStatsList2) {
                if (stats.getLastTimeUsed() > searchInterval || runningAppsOnly)
                    usageStatsList3.add(stats);
            }

            // Sort apps by either most recently used, or most time used
            if (!runningAppsOnly) {
                if (sortOrder.contains("most_used")) {
                    Collections.sort(usageStatsList3, (us1, us2) -> Long.compare(us2.getTotalTimeInForeground(),
                            us1.getTotalTimeInForeground()));
                } else {
                    Collections.sort(usageStatsList3,
                            (us1, us2) -> Long.compare(us2.getLastTimeUsed(), us1.getLastTimeUsed()));
                }
            }

            // Filter out any duplicate entries
            List<String> applicationIds = new ArrayList<>();
            for (AppEntry stats : usageStatsList3) {
                if (!applicationIds.contains(stats.getPackageName())) {
                    usageStatsList4.add(stats);
                    applicationIds.add(stats.getPackageName());
                }
            }

            // Filter out the currently running foreground app, if requested by the user
            if (pref.getBoolean("hide_foreground", false)) {
                UsageStatsManager mUsageStatsManager = (UsageStatsManager) getSystemService(
                        USAGE_STATS_SERVICE);
                UsageEvents events = mUsageStatsManager.queryEvents(searchInterval, System.currentTimeMillis());
                UsageEvents.Event eventCache = new UsageEvents.Event();
                String currentForegroundApp = null;

                while (events.hasNextEvent()) {
                    events.getNextEvent(eventCache);

                    if (eventCache.getEventType() == UsageEvents.Event.MOVE_TO_FOREGROUND) {
                        if (!(eventCache.getPackageName().contains(BuildConfig.BASE_APPLICATION_ID)
                                && !eventCache.getClassName().equals(MainActivity.class.getCanonicalName())
                                && !eventCache.getClassName().equals(HomeActivity.class.getCanonicalName())
                                && !eventCache.getClassName()
                                        .equals(InvisibleActivityFreeform.class.getCanonicalName())))
                            currentForegroundApp = eventCache.getPackageName();
                    }
                }

                if (!applicationIdsToRemove.contains(currentForegroundApp))
                    applicationIdsToRemove.add(currentForegroundApp);
            }

            for (AppEntry stats : usageStatsList4) {
                if (!applicationIdsToRemove.contains(stats.getPackageName())) {
                    usageStatsList5.add(stats);
                }
            }

            // Truncate list to a maximum length
            if (usageStatsList5.size() > maxNumOfEntries)
                usageStatsList6 = usageStatsList5.subList(0, maxNumOfEntries);
            else
                usageStatsList6 = usageStatsList5;

            // Determine if we need to reverse the order
            boolean needToReverseOrder;
            switch (U.getTaskbarPosition(this)) {
            case "bottom_right":
            case "top_right":
                needToReverseOrder = sortOrder.contains("false");
                break;
            default:
                needToReverseOrder = sortOrder.contains("true");
                break;
            }

            if (needToReverseOrder) {
                Collections.reverse(usageStatsList6);
            }

            // Generate the AppEntries for TaskbarAdapter
            int number = usageStatsList6.size() == maxNumOfEntries
                    ? usageStatsList6.size() - realNumOfPinnedApps
                    : usageStatsList6.size();

            UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
            LauncherApps launcherApps = (LauncherApps) getSystemService(Context.LAUNCHER_APPS_SERVICE);

            final List<UserHandle> userHandles = userManager.getUserProfiles();

            for (int i = 0; i < number; i++) {
                for (UserHandle handle : userHandles) {
                    String packageName = usageStatsList6.get(i).getPackageName();
                    List<LauncherActivityInfo> list = launcherApps.getActivityList(packageName, handle);
                    if (!list.isEmpty()) {
                        // Google App workaround
                        if (!packageName.equals("com.google.android.googlequicksearchbox"))
                            launcherAppCache.add(list.get(0));
                        else {
                            boolean added = false;
                            for (LauncherActivityInfo info : list) {
                                if (info.getName()
                                        .equals("com.google.android.googlequicksearchbox.SearchActivity")) {
                                    launcherAppCache.add(info);
                                    added = true;
                                }
                            }

                            if (!added)
                                launcherAppCache.add(list.get(0));
                        }

                        AppEntry newEntry = new AppEntry(packageName, null, null, null, false);

                        newEntry.setUserId(userManager.getSerialNumberForUser(handle));
                        entries.add(newEntry);

                        break;
                    }
                }
            }
        }

        while (entries.size() > maxNumOfEntries) {
            try {
                entries.remove(entries.size() - 1);
                launcherAppCache.remove(launcherAppCache.size() - 1);
            } catch (ArrayIndexOutOfBoundsException e) {
                /* Gracefully fail */ }
        }

        // Determine if we need to reverse the order again
        if (U.getTaskbarPosition(this).contains("vertical")) {
            Collections.reverse(entries);
            Collections.reverse(launcherAppCache);
        }

        // Now that we've generated the list of apps,
        // we need to determine if we need to redraw the Taskbar or not
        boolean shouldRedrawTaskbar = firstRefresh;

        List<String> finalApplicationIds = new ArrayList<>();
        for (AppEntry entry : entries) {
            finalApplicationIds.add(entry.getPackageName());
        }

        if (finalApplicationIds.size() != currentTaskbarIds.size() || numOfPinnedApps != realNumOfPinnedApps)
            shouldRedrawTaskbar = true;
        else {
            for (int i = 0; i < finalApplicationIds.size(); i++) {
                if (!finalApplicationIds.get(i).equals(currentTaskbarIds.get(i))) {
                    shouldRedrawTaskbar = true;
                    break;
                }
            }
        }

        if (shouldRedrawTaskbar) {
            currentTaskbarIds = finalApplicationIds;
            numOfPinnedApps = realNumOfPinnedApps;

            UserManager userManager = (UserManager) getSystemService(USER_SERVICE);

            int launcherAppCachePos = -1;
            for (int i = 0; i < entries.size(); i++) {
                if (entries.get(i).getComponentName() == null) {
                    launcherAppCachePos++;
                    LauncherActivityInfo appInfo = launcherAppCache.get(launcherAppCachePos);
                    String packageName = entries.get(i).getPackageName();

                    entries.remove(i);

                    AppEntry newEntry = new AppEntry(packageName, appInfo.getComponentName().flattenToString(),
                            appInfo.getLabel().toString(), IconCache.getInstance(TaskbarService.this)
                                    .getIcon(TaskbarService.this, pm, appInfo),
                            false);

                    newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
                    entries.add(i, newEntry);
                }
            }

            final int numOfEntries = Math.min(entries.size(), maxNumOfEntries);

            handler.post(() -> {
                if (numOfEntries > 0 || fullLength) {
                    ViewGroup.LayoutParams params = scrollView.getLayoutParams();
                    DisplayMetrics metrics = getResources().getDisplayMetrics();
                    int recentsSize = getResources().getDimensionPixelSize(R.dimen.icon_size) * numOfEntries;
                    float maxRecentsSize = fullLength ? Float.MAX_VALUE : recentsSize;

                    if (U.getTaskbarPosition(TaskbarService.this).contains("vertical")) {
                        int maxScreenSize = metrics.heightPixels - U.getStatusBarHeight(TaskbarService.this)
                                - U.getBaseTaskbarSize(TaskbarService.this);

                        params.height = (int) Math.min(maxRecentsSize, maxScreenSize)
                                + getResources().getDimensionPixelSize(R.dimen.divider_size);

                        if (fullLength && U.getTaskbarPosition(this).contains("bottom")) {
                            try {
                                Space whitespace = (Space) layout.findViewById(R.id.whitespace);
                                ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
                                params2.height = maxScreenSize - recentsSize;
                                whitespace.setLayoutParams(params2);
                            } catch (NullPointerException e) {
                                /* Gracefully fail */ }
                        }
                    } else {
                        int maxScreenSize = metrics.widthPixels - U.getBaseTaskbarSize(TaskbarService.this);

                        params.width = (int) Math.min(maxRecentsSize, maxScreenSize)
                                + getResources().getDimensionPixelSize(R.dimen.divider_size);

                        if (fullLength && U.getTaskbarPosition(this).contains("right")) {
                            try {
                                Space whitespace = (Space) layout.findViewById(R.id.whitespace);
                                ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
                                params2.width = maxScreenSize - recentsSize;
                                whitespace.setLayoutParams(params2);
                            } catch (NullPointerException e) {
                                /* Gracefully fail */ }
                        }
                    }

                    scrollView.setLayoutParams(params);

                    taskbar.removeAllViews();
                    for (int i = 0; i < entries.size(); i++) {
                        taskbar.addView(getView(entries, i));
                    }

                    isShowingRecents = true;
                    if (shouldRefreshRecents && scrollView.getVisibility() != View.VISIBLE) {
                        if (firstRefresh)
                            scrollView.setVisibility(View.INVISIBLE);
                        else
                            scrollView.setVisibility(View.VISIBLE);
                    }

                    if (firstRefresh && scrollView.getVisibility() != View.VISIBLE)
                        new Handler().post(() -> {
                            switch (U.getTaskbarPosition(TaskbarService.this)) {
                            case "bottom_left":
                            case "bottom_right":
                            case "top_left":
                            case "top_right":
                                if (sortOrder.contains("false"))
                                    scrollView.scrollTo(0, 0);
                                else if (sortOrder.contains("true"))
                                    scrollView.scrollTo(taskbar.getWidth(), taskbar.getHeight());
                                break;
                            case "bottom_vertical_left":
                            case "bottom_vertical_right":
                            case "top_vertical_left":
                            case "top_vertical_right":
                                if (sortOrder.contains("false"))
                                    scrollView.scrollTo(taskbar.getWidth(), taskbar.getHeight());
                                else if (sortOrder.contains("true"))
                                    scrollView.scrollTo(0, 0);
                                break;
                            }

                            if (shouldRefreshRecents) {
                                scrollView.setVisibility(View.VISIBLE);
                            }
                        });
                } else {
                    isShowingRecents = false;
                    scrollView.setVisibility(View.GONE);
                }
            });
        }
    } else if (firstRefresh || currentTaskbarIds.size() > 0) {
        currentTaskbarIds.clear();
        handler.post(() -> {
            isShowingRecents = false;
            scrollView.setVisibility(View.GONE);
        });
    }
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static Intent createHomeIntent() {
    Intent intent = createHomeDockIntent();
    if (intent != null) {
        try {//from  w w w .  j a  v a 2s  . co m
            return intent;
        } catch (ActivityNotFoundException e) {
        }
    }
    intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_HOME);
    return intent;
}

From source file:com.cpic.taylor.logistics.activity.HomeActivity.java

@Override
public void onBackPressed() {
    //        // ?
    //        long currentTime = System.currentTimeMillis();
    //        long dTime = currentTime - lastTime;
    ///*from   w ww. j  a va  2 s  . co m*/
    //        if (dTime < 2000) {
    //            finish();
    //        } else {
    //            showShortToast("??");
    //            lastTime = currentTime;
    //        }
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// ?
    intent.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(intent);
}

From source file:com.birdeye.MainActivity.java

@OnClick(R.id.apply)
void onClick() {//www.  jav  a2s  .  c o  m

    if (Globals.hasPaid) {
        Prefs.usernames.set(TextViews.trimmed(usernames));
        Prefs.hashtags.set(TextViews.trimmed(hashtags));
        Prefs.message1.set(TextViews.trimmed(message1));
        Prefs.message2.set(TextViews.trimmed(message2));
        Prefs.message3.set(TextViews.trimmed(message3));

        Prefs.message4.set(TextViews.trimmed(message4));
        Prefs.message5.set(TextViews.trimmed(message5));
        Prefs.message6.set(TextViews.trimmed(message6));
        Prefs.message7.set(TextViews.trimmed(message7));
        Prefs.message8.set(TextViews.trimmed(message8));
        Prefs.message9.set(TextViews.trimmed(message9));
        Prefs.message10.set(TextViews.trimmed(message10));
        Prefs.message11.set(TextViews.trimmed(message11));
        Prefs.message12.set(TextViews.trimmed(message12));
        Prefs.message13.set(TextViews.trimmed(message13));
        Prefs.message14.set(TextViews.trimmed(message14));
        Prefs.message15.set(TextViews.trimmed(message15));
        Prefs.message16.set(TextViews.trimmed(message16));
        Prefs.message17.set(TextViews.trimmed(message17));
        Prefs.message18.set(TextViews.trimmed(message18));
        Prefs.message19.set(TextViews.trimmed(message19));
        Prefs.message20.set(TextViews.trimmed(message20));
        Prefs.message21.set(TextViews.trimmed(message21));
        Prefs.message22.set(TextViews.trimmed(message22));
        Prefs.message23.set(TextViews.trimmed(message23));
        Prefs.message24.set(TextViews.trimmed(message24));
        Prefs.message25.set(TextViews.trimmed(message25));

    } else {
        Prefs.usernames.set(TextViews.trimmed(usernames));
        Prefs.hashtags.set(TextViews.trimmed(hashtags));
        Prefs.message1.set(TextViews.trimmed(message1));
        Prefs.message2.set(TextViews.trimmed(message2));
        Prefs.message3.set(TextViews.trimmed(message3));
    }

    if (canEnable()) {
        textLayout(usernames).setError(null);
        textLayout(usernames).setErrorEnabled(false);
        textLayout(hashtags).setError(null);
        textLayout(hashtags).setErrorEnabled(false);

        Realm.getDefaultInstance().executeTransactionAsync(realm -> {
            final RealmResults<LocalTweet> tweets = realm.where(LocalTweet.class).equalTo("replied", false)
                    .findAll();
            for (LocalTweet replied : tweets) {
                replied.deleteFromRealm();
            }
        });
        Prefs.lastId.set(null);

        //noinspection ConstantConditions
        if (Prefs.enable.get()) {
            final Intent svc = EyeService.create(this);
            stopService(svc);
            startService(svc);

            startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    } else {
        final String err = getString(R.string.at_least_one_user);
        textLayout(usernames).setError(err);
        textLayout(hashtags).setError(err);

        Prefs.enable.set(false);
        initial(false);
    }
}

From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java

public void onBackPressed() {
    Intent setIntent = new Intent(Intent.ACTION_MAIN);
    setIntent.addCategory(Intent.CATEGORY_HOME);
    setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(setIntent);//from www.  ja va2s.c  o  m
}

From source file:com.tt.jobtracker.MainActivity.java

@Override
public void onBackPressed() {
    if (Shared.onbackpress == true) {
        if (back_pressed + 2000 > System.currentTimeMillis()) {
            //    super.onBackPressed();
            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);/*w ww .j a  va  2  s .c om*/
        } else {
            Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT).show();
            back_pressed = System.currentTimeMillis();
        }
    } else {
        super.onBackPressed();
    }
}