Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

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

Prototype

String ACTION_MAIN

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

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

Usage

From source file:g7.bluesky.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//from ww  w. java 2  s  .  c om
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        Folder openFolder = mWorkspace.getOpenFolder();
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        boolean moveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null
                && moveToDefaultScreen) {
            mWorkspace.moveToDefaultScreen(true);
        }

        closeFolder();
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps customize page
        if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.reset();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }
}

From source file:com.httrack.android.HTTrackActivity.java

/** Navigate back to home, without killing us. **/
private void goToHome() {
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);/*from   ww  w  . j av a2s .  co  m*/
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

private List<ResolveInfo> getAllLauncherIntentResolversSorted() {
    final Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> launcherIntentResolvers = mPackageManager.queryIntentActivities(launcherIntent, 0);
    Collections.sort(launcherIntentResolvers, new ResolveInfo.DisplayNameComparator(mPackageManager));
    return launcherIntentResolvers;
}

From source file:com.android.mms.ui.MessageUtils.java

private static List<String> getHomes(Context context) {
    MmsLog.d(TAG, "DialogModeActivity.getHomes");

    List<String> names = new ArrayList<String>();
    PackageManager packageManager = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo ri : resolveInfo) {
        names.add(ri.activityInfo.packageName);
        MmsLog.d(TAG, "package name=" + ri.activityInfo.packageName + " class name=" + ri.activityInfo.name);
    }/*  w ww  .  j  a va2s . co  m*/
    return names;
}

From source file:com.hichinaschool.flashcards.anki.DeckPicker.java

/**
 * Creates an intent to load a deck given the full pathname of it. The constructed intent is equivalent (modulo the
 * extras) to the open used by the launcher shortcut, which means it will not open a new study options window but
 * bring the existing one to the front./* www.j  av  a  2s .  com*/
 */
public static Intent getLoadDeckIntent(Context context, long deckId) {
    Intent loadDeckIntent = new Intent(context, DeckPicker.class);
    loadDeckIntent.setAction(Intent.ACTION_MAIN);
    loadDeckIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    loadDeckIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    loadDeckIntent.putExtra(EXTRA_DECK_ID, deckId);
    return loadDeckIntent;
}

From source file:com.example.sensingapp.SensingApp.java

/** Called when the activity is first created. */
@Override//from   w  w w .  ja va 2  s .co  m
public void onCreate(Bundle savedInstanceState) {
    int i;
    Location location = null;

    super.onCreate(savedInstanceState);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    try {
        Class.forName("android.os.AsyncTask");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    m_smSurScan = (SensorManager) getSystemService(SENSOR_SERVICE);

    PackageManager pm = getPackageManager();
    m_riHome = pm.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    m_nBufferSize = AudioRecord.getMinBufferSize(m_nAudioSampleRate, AudioFormat.CHANNEL_IN_STEREO,
            AudioFormat.ENCODING_PCM_16BIT);

    m_tmCellular = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    checkSensorAvailability();

    //Get Existing Project Name and Existing User Name
    preconfigSetting();

    /* When the power button is pressed and the screen goes off, the sensors will stop work by default,
     * Here keep the CPU on to keep sensor alive and also use SCREEN_OFF notification to re-enable GPS/WiFi
     */
    PowerManager pwrManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    m_wakeLock = pwrManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);

    registerReceiver(m_ScreenOffReceiver, filter);

    show_screen1();
}

From source file:com.android.tv.MainActivity.java

@Override
public void onBackPressed() {
    // The activity should be returned to the caller of this activity
    // when the mSource is not null.
    if (!mOverlayManager.getSideFragmentManager().isActive() && isPlaying() && mSource == null) {
        // If back key would exit TV app,
        // show McLauncher instead so we can get benefit of McLauncher's shyMode.
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startActivity(startMain);// ww w.  j av a2  s  . com
    } else {
        super.onBackPressed();
    }
}

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  w  w . j  a v  a2s  .  c  om
        return super.onKeyDown(keyCode, event);
    }
}

From source file:org.chromium.chrome.browser.tab.Tab.java

/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 *//*  w  w  w.  j av a  2  s .c  o  m*/
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String StartJavaPrg(String[] sArgs, Intent preIntent) {
    String sRet = "";
    String sArgList = "";
    String sUrl = "";
    //        String sRedirFileName = "";
    Intent prgIntent = null;/*from  w  w  w.j  av  a  2  s .  com*/

    Context ctx = contextWrapper.getApplicationContext();
    PackageManager pm = ctx.getPackageManager();

    if (preIntent == null)
        prgIntent = new Intent();
    else
        prgIntent = preIntent;

    prgIntent.setPackage(sArgs[0]);
    prgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Get the main activity for this package
    try {
        final ComponentName c = pm.getLaunchIntentForPackage(sArgs[0]).getComponent();
        prgIntent.setClassName(c.getPackageName(), c.getClassName());
    } catch (Exception e) {
        e.printStackTrace();
        return "Unable to find main activity for package: " + sArgs[0];
    }

    if (sArgs.length > 1) {
        if (sArgs[0].contains("android.browser"))
            prgIntent.setAction(Intent.ACTION_VIEW);
        else
            prgIntent.setAction(Intent.ACTION_MAIN);

        if (sArgs[0].contains("fennec") || sArgs[0].contains("firefox")) {
            sArgList = "";
            sUrl = "";

            for (int lcv = 1; lcv < sArgs.length; lcv++) {
                if (sArgs[lcv].contains("://")) {
                    prgIntent.setAction(Intent.ACTION_VIEW);
                    sUrl = sArgs[lcv];
                } else {
                    if (sArgs[lcv].equals(">")) {
                        lcv++;
                        if (lcv < sArgs.length)
                            lcv++;
                        //                                sRedirFileName = sArgs[lcv++];
                    } else
                        sArgList += " " + sArgs[lcv];
                }
            }

            if (sArgList.length() > 0)
                prgIntent.putExtra("args", sArgList.trim());

            if (sUrl.length() > 0)
                prgIntent.setData(Uri.parse(sUrl.trim()));
        } else {
            for (int lcv = 1; lcv < sArgs.length; lcv++)
                sArgList += " " + sArgs[lcv];

            prgIntent.setData(Uri.parse(sArgList.trim()));
        }
    } else {
        prgIntent.setAction(Intent.ACTION_MAIN);
    }

    try {
        contextWrapper.startActivity(prgIntent);
        FindProcThread findProcThrd = new FindProcThread(contextWrapper, sArgs[0]);
        findProcThrd.start();
        findProcThrd.join(7000);
        if (!findProcThrd.bFoundIt && !findProcThrd.bStillRunning) {
            sRet = "Unable to start " + sArgs[0] + "";
        }
    } catch (ActivityNotFoundException anf) {
        anf.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    ctx = null;
    return (sRet);
}