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:de.blinkt.openvpn.ActivityDashboard.java

private void startVPN(VpnProfile profile) {
    //Profile Manger saves profile

    Intent intent = new Intent(this, LaunchVPN.class);
    intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
    Log.d("extra", LaunchVPN.EXTRA_KEY + "profile UUID    " + profile.getUUID().toString());
    intent.setAction(Intent.ACTION_MAIN);
    startActivity(intent);/*from   w  w  w.  ja v a2 s .c  om*/
}

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

private boolean processIntent(Intent intent) {
    boolean isDeepLink = false;

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        /* Do a search by name, launched from the quick search */
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        SearchCriteria sc = new SearchCriteria();
        sc.name = query;/* ww  w .j  a va  2  s.  com*/
        args.putSerializable(SearchViewFragment.CRITERIA, sc);
        selectItem(R.string.main_card_search, args, false,
                true); /* Don't clear backstack, do force the intent */

    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        boolean shouldSelectItem = true;

        Uri data = intent.getData();
        Bundle args = new Bundle();
        assert data != null;

        boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */
        if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) {
            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                String queryParam;
                if ((queryParam = data.getQueryParameter("multiverseid")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam),
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else if ((queryParam = data.getQueryParameter("name")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByName(queryParam,
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            true, database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else {
                    throw new Exception("Not Found");
                }
            } catch (Exception e) {
                /* empty cursor, just return */
                ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                this.finish();
                shouldSelectItem = false;
            } finally {
                DatabaseManager.getInstance(this, false).closeDatabase(false);
            }
        } else if (data.getAuthority().contains("CardSearchProvider")) {
            /* User clicked a card in the quick search autocomplete, jump right to it */
            args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                    new long[] { Long.parseLong(data.getLastPathSegment()) });
            shouldClearFragmentStack = false; /* Don't clear backstack for search intents */
        } else {
            /* User clicked a deep link, jump to the card(s) */
            isDeepLink = true;

            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                Cursor cursor = null;
                boolean screenLaunched = false;
                if (data.getScheme().toLowerCase().equals("card")
                        && data.getAuthority().toLowerCase().equals("multiverseid")) {
                    if (data.getLastPathSegment() == null) {
                        /* Home screen deep link */
                        launchHomeScreen();
                        screenLaunched = true;
                        shouldSelectItem = false;
                    } else {
                        try {
                            /* Don't clear the fragment stack for internal links (thanks Meld cards) */
                            if (data.getPathSegments().contains("internal")) {
                                shouldClearFragmentStack = false;
                            }
                            cursor = CardDbAdapter.fetchCardByMultiverseId(
                                    Long.parseLong(data.getLastPathSegment()),
                                    new String[] {
                                            CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                                    database);
                        } catch (NumberFormatException e) {
                            cursor = null;
                        }
                    }
                }

                if (cursor != null) {
                    if (cursor.getCount() != 0) {
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    } else {
                        /* empty cursor, just return */
                        ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                        this.finish();
                        shouldSelectItem = false;
                    }
                    cursor.close();
                } else if (!screenLaunched) {
                    /* null cursor, just return */
                    ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                    this.finish();
                    shouldSelectItem = false;
                }
            } catch (FamiliarDbException e) {
                e.printStackTrace();
            }
            DatabaseManager.getInstance(this, false).closeDatabase(false);
        }
        args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0);
        if (shouldSelectItem) {
            selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true);
        }
    } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) {
        selectItem(R.string.main_timer, null, true, false);
    } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) {
        selectItem(R.string.main_card_search, null, true, false);
    } else if (ACTION_LIFE.equals(intent.getAction())) {
        selectItem(R.string.main_life_counter, null, true, false);
    } else if (ACTION_DICE.equals(intent.getAction())) {
        selectItem(R.string.main_dice, null, true, false);
    } else if (ACTION_TRADE.equals(intent.getAction())) {
        selectItem(R.string.main_trade, null, true, false);
    } else if (ACTION_MANA.equals(intent.getAction())) {
        selectItem(R.string.main_mana_pool, null, true, false);
    } else if (ACTION_WISH.equals(intent.getAction())) {
        selectItem(R.string.main_wishlist, null, true, false);
    } else if (ACTION_RULES.equals(intent.getAction())) {
        selectItem(R.string.main_rules, null, true, false);
    } else if (ACTION_JUDGE.equals(intent.getAction())) {
        selectItem(R.string.main_judges_corner, null, true, false);
    } else if (ACTION_MOJHOSTO.equals(intent.getAction())) {
        selectItem(R.string.main_mojhosto, null, true, false);
    } else if (ACTION_PROFILE.equals(intent.getAction())) {
        selectItem(R.string.main_profile, null, true, false);
    } else if (ACTION_DECKLIST.equals(intent.getAction())) {
        selectItem(R.string.main_decklist, null, true, false);
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        /* App launched as regular, show the default fragment if there isn't one already */
        if (getSupportFragmentManager().getFragments() == null) {
            launchHomeScreen();
        }
    } else {
        /* Some unknown intent, just finish */
        finish();
    }

    mDrawerList.setItemChecked(mCurrentFrag, true);
    return isDeepLink;
}

From source file:csh.cryptonite.Cryptonite.java

public void launchTerm(boolean root) {
    /* Is a reminal emulator running? */

    /* If Terminal Emulator is not installed or outdated,
     * offer to download/*from w  w w . j a v  a 2s  . c  o m*/
     */
    if (hasExtterm(getBaseContext()) != TERM_AVAILABLE) {
        TermUnavailableDialogFragment newFragment = TermUnavailableDialogFragment.newInstance();
        newFragment.show(getSupportFragmentManager(), "dialog");
    } else {
        ComponentName termComp = new ComponentName("jackpal.androidterm", "jackpal.androidterm.Term");
        try {
            PackageInfo pinfo = getBaseContext().getPackageManager().getPackageInfo(termComp.getPackageName(),
                    0);
            String patchVersion = pinfo.versionName;
            Log.v(TAG, "Terminal Emulator version: " + patchVersion);
            int patchCode = pinfo.versionCode;

            if (patchCode < 32) {
                showAlert(R.string.error, R.string.app_terminal_outdated);
            } else if (patchCode < 43) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(termComp);
                runTerm(intent, extTermRunning(), root);
            } else {
                ComponentName remoteComp = new ComponentName("jackpal.androidterm",
                        "jackpal.androidterm.RemoteInterface");
                Intent intent = new Intent("jackpal.androidterm.RUN_SCRIPT");
                intent.setComponent(remoteComp);
                runTerm(intent, false, root);
            }

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(Cryptonite.this, R.string.app_terminal_missing, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:it.chefacile.app.MainActivity.java

@Override
public void onBackPressed() {
    new AlertDialog.Builder(this).setIcon(R.drawable.logo).setTitle("Exit").setMessage("Are you sure?")
            .setPositiveButton("yes", new DialogInterface.OnClickListener() {
                @Override/*from  w ww  . ja v a2 s .c om*/
                public void onClick(DialogInterface dialog, int which) {

                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//***Change Here***
                    startActivity(intent);
                    finish();
                    System.exit(0);
                }
            }).setNegativeButton("no", null).show();
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/** Returns an Intent to launch Call Settings screen */
public static Intent getCallSettingsIntent() {
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return intent;
}

From source file:com.android.launcher3.Utilities.java

/**
 * Returns true if the intent is a valid launch intent for a launcher activity of an app.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file.//from ww w .j av  a 2  s .  c o  m
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
public static boolean isLauncherAppTarget(Intent launchIntent) {
    if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && TextUtils.isEmpty(launchIntent.getDataString())) {
        // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
        Bundle extras = launchIntent.getExtras();
        if (extras == null) {
            return true;
        } else {
            Set<String> keys = extras.keySet();
            return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE);
        }
    }
    ;
    return false;
}

From source file:com.example.search.car.pools.welcome.java

public void onBackPressed() {
    if (canExit) {
        super.onBackPressed();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);//from  ww  w  .j  a  v  a 2s.c o m
    } else {
        // Fragment fm = getFragmentManager().findFragmentByTag("Search");
        if (frag_tag != "Search") {
            svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1);
            iv_search.setImageDrawable(svg_search.createPictureDrawable());
            rlSearch.setBackgroundColor(Color.parseColor("#00ca98"));
            l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));

            svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard);
            iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable());
            rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50"));
            l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue));
            svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city);
            iv_cities.setImageDrawable(svg_cities.createPictureDrawable());
            rlCities.setBackgroundColor(Color.parseColor("#2C3E50"));
            l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue));

            FragmentManager fm = getFragmentManager();
            FragmentTransaction fragmentTransaction = fm.beginTransaction();
            fragmentTransaction.replace(R.id.content_frame, new Search());
            fragmentTransaction.commit();
            frag_tag = "Search";
        } else {
            canExit = true;
            Toast.makeText(getApplicationContext(), "Press again to exit", Toast.LENGTH_SHORT).show();
        }

    }
    mHandler.sendEmptyMessageDelayed(1, 2000/* time interval to next press in milli second */);// if not
    // pressed
    // within
    // 2
    // seconds
    // then
    // will
    // be
    // setted(canExit)
    // as
    // false
}

From source file:com.dsdar.thosearoundme.TeamViewActivity.java

@Override
public void onBackPressed() {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("Exit Application?");
    alertDialogBuilder.setMessage("Click yes to exit!").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Remove Service
                    stopService(new Intent(getBaseContext(), LocationUpdates.class));
                    // stopService(new Intent(getBaseContext(),
                    // LocationService.class));
                    if (itsLocationUpdates != null)
                        itsLocationUpdates.disconnectLocationClient();
                    mHandlerTaskServiceStop = new Runnable() {
                        @Override
                        public void run() {
                            Log.d("tmf", "calling mHandlerTaskServiceStop.......");
                            // Get and set team members location in
                            // map

                            // finish();
                            //                                        moveTaskToBack(true);
                            //
                            //                                        Intent amyProfileIntent = new Intent().setClass(
                            //                                                TeamViewActivity.this, WelcomeActivity.class);
                            //                                        startActivity(amyProfileIntent);
                            //
                            //
                            //                                        android.os.Process
                            //                                                .killProcess(android.os.Process
                            //                                                        .myPid());
                            //                                        System.exit(1);
                            Intent intent = new Intent(Intent.ACTION_MAIN);
                            intent.addCategory(Intent.CATEGORY_HOME);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }/*  ww  w  .  j  a v  a2 s .c  o m*/
                    };
                    itsHandlerServiceStop.postDelayed(mHandlerTaskServiceStop, 1500);

                }
            })

            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    dialog.cancel();
                }
            });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

private void makeForegroundNotify() {
    /* For starting main activity */
    Intent startupIntent = new Intent(getApplicationContext(), MainActivity.class);
    startupIntent.setAction(Intent.ACTION_MAIN);
    startupIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    startupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent startupPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, startupIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    foregroundNotify = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_app_notification).setContentIntent(startupPendingIntent)
            .setContentTitle(getString(R.string.app_running_in_the_background))
            .setTicker(getString(R.string.app_running_in_the_background))
            .setContentText((isNetworkOnline ? getString(R.string.network_online)
                    : getString(R.string.network_offline)))
            .setWhen(System.currentTimeMillis());

    /* For calling add torrent dialog */
    Intent addTorrentIntent = new Intent(getApplicationContext(), NotificationReceiver.class);
    addTorrentIntent.setAction(NotificationReceiver.NOTIFY_ACTION_ADD_TORRENT);

    PendingIntent addTorrentPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
            addTorrentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action addTorrentAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_add_white_36dp, getString(R.string.add), addTorrentPendingIntent).build();

    foregroundNotify.addAction(addTorrentAction);

    /* For shutdown activity and service */
    Intent shutdownIntent = new Intent(getApplicationContext(), NotificationReceiver.class);
    shutdownIntent.setAction(NotificationReceiver.NOTIFY_ACTION_SHUTDOWN_APP);

    PendingIntent shutdownPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, shutdownIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action shutdownAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_power_settings_new_white_24dp, getString(R.string.shutdown), shutdownPendingIntent)
                    .build();// ww  w .ja v a  2  s .  c o  m

    foregroundNotify.addAction(shutdownAction);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        foregroundNotify.setCategory(Notification.CATEGORY_SERVICE);
    }

    /* Disallow killing the service process by system */
    startForeground(SERVICE_STARTED_NOTIFICATION_ID, foregroundNotify.build());
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }//w  w w.  j ava2  s . co  m
    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;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();
        mWorkspace.requestFocus();

        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 (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}