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:kr.go.hf.hfappandroid.app.intro.IntroActivity.java

/**
 * ???????VGuard??( ?? ? ?? )/*from  w  w w.  ja  va  2 s  . c o  m*/
 * 
 * @date BSJ 13/05/06
*/
private void startVGuard() {
    if (!Common.isPackageInstalled(this, Constants.VGUARD_PACKAGE_NAME)) {
        dialogInstallVGuard();
        return;
    }

    ComponentName cn = new ComponentName(Constants.VGUARD_PACKAGE_NAME,
            Constants.VGUARD_PACKAGE_NAME + Constants.VGUARD_ACTIVITY_NAME);
    Intent actIntent = new Intent(Intent.ACTION_MAIN);
    actIntent.setComponent(cn);
    actIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    actIntent.putExtra("LicenseKey", Constants.VGUARD_LICENSE_KEY);
    startActivityForResult(actIntent, REQUEST_START_VGUARD);
    CLog.e("VGuard", "start");
}

From source file:com.hippo.scene.StageActivity.java

@Override
protected final void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mStageId = savedInstanceState.getInt(KEY_STAGE_ID, IntIdGenerator.INVALID_ID);
        ArrayList<String> list = savedInstanceState.getStringArrayList(KEY_SCENE_TAG_LIST);
        mSceneTagList.addAll(list);/*w ww .  j a v a 2 s. c  om*/
        mDelaySceneTagList.addAll(list);
        mIdGenerator.lazySet(savedInstanceState.getInt(KEY_NEXT_ID));
    }

    if (mStageId == IntIdGenerator.INVALID_ID) {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this);
    } else {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this, mStageId);
    }

    // Create layout
    onCreate2(savedInstanceState);

    Intent intent = getIntent();
    if (savedInstanceState == null) {
        if (intent != null) {
            String action = intent.getAction();
            if (Intent.ACTION_MAIN.equals(action)) {
                Announcer announcer = getLaunchAnnouncer();
                if (announcer != null) {
                    startScene(announcer);
                    return;
                }
            } else if (ACTION_START_SCENE.equals(action)) {
                if (startSceneFromIntent(intent)) {
                    return;
                }
            }
        }

        // Can't recognize intent
        onUnrecognizedIntent(intent);
    }
}

From source file:com.amaze.carbonfilemanager.activities.PreferencesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Navigate "up" the demo structure to the launchpad activity.
        if (selectedItem != START_PREFERENCE && changed)
            restartPC(this);
        else if (selectedItem != START_PREFERENCE) {
            selectItem(START_PREFERENCE);
        } else {/* w w w. j a va 2s  .  com*/
            Intent in = new Intent(PreferencesActivity.this, MainActivity.class);
            in.setAction(Intent.ACTION_MAIN);
            in.setAction(Intent.CATEGORY_LAUNCHER);

            final int enter_anim = android.R.anim.fade_in;
            final int exit_anim = android.R.anim.fade_out;
            Activity activity = this;
            activity.overridePendingTransition(enter_anim, exit_anim);
            activity.finish();
            activity.overridePendingTransition(enter_anim, exit_anim);
            activity.startActivity(in);
        }
        return true;
    }
    return true;
}

From source file:com.redhorse.quickstart.AppConfig.java

private void loadApps() {
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    mAllApps = getPackageManager().queryIntentActivities(mainIntent, 0);
    mApps = new ArrayList<ResolveInfo>();
    mApps2 = new ArrayList<ResolveInfo>();
    Cursor c = dbStart.getAllItems();
    Iterator it1 = mAllApps.iterator();
    while (it1.hasNext()) {
        boolean found = false;
        ResolveInfo info = (ResolveInfo) it1.next();
        if (c.moveToFirst()) {
            do {/*from  w  w w.jav a  2s .co m*/
                int idColumn = c.getColumnIndex(dbStart.KEY_ROWID);
                int pkgnameColumn = c.getColumnIndex(dbStart.KEY_PKGNAME);
                int appnameColumn = c.getColumnIndex(dbStart.KEY_APPNAME);
                int contentColumn = c.getColumnIndex(dbStart.KEY_CONTENT);
                if (c.getString(pkgnameColumn).equals(info.activityInfo.packageName)
                        && c.getString(appnameColumn).equalsIgnoreCase(info.activityInfo.name)) {
                    found = true;
                    break;
                }
            } while (c.moveToNext());
        }
        if (!found)
            if (!info.activityInfo.packageName.equalsIgnoreCase("com.redhorse.quickstart"))
                mApps.add(info);
    }
    if (c.moveToFirst()) {
        do {
            int idColumn = c.getColumnIndex(dbStart.KEY_ROWID);
            int pkgnameColumn = c.getColumnIndex(dbStart.KEY_PKGNAME);
            int appnameColumn = c.getColumnIndex(dbStart.KEY_APPNAME);
            int contentColumn = c.getColumnIndex(dbStart.KEY_CONTENT);
            it1 = mAllApps.iterator();
            boolean found = false;
            ResolveInfo info = null;
            while (it1.hasNext()) {
                info = (ResolveInfo) it1.next();
                if (c.getString(pkgnameColumn).equals(info.activityInfo.packageName)
                        && c.getString(appnameColumn).equalsIgnoreCase(info.activityInfo.name)) {
                    found = true;
                    break;
                }
            }
            if (found)
                if (!info.activityInfo.packageName.equalsIgnoreCase("com.redhorse.quickstart"))
                    mApps2.add(info);
        } while (c.moveToNext());
    }
    c.close();
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

@Nullable
private static String buildActivityList(Context context, File folder) {
    try {/* www  . j av  a 2s .c  om*/
        File fileDir = new File(folder.toString() + "/" + "activity_list.xml");
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> appList = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.GET_RESOLVED_FILTER);

        try {
            Collections.sort(appList, new ResolveInfo.DisplayNameComparator(context.getPackageManager()));
        } catch (Exception ignored) {
        }

        boolean first = true;
        for (ResolveInfo app : appList) {

            if (first) {
                first = false;
                out.append("<!-- ACTIVITY LIST -->");
                out.append("\n\n\n");
            }

            String name = app.activityInfo.loadLabel(context.getPackageManager()).toString();
            String activity = app.activityInfo.packageName + "/" + app.activityInfo.name;
            out.append("<!-- ").append(name).append(" -->");
            out.append("\n").append(activity);
            out.append("\n\n");
        }
        out.flush();
        out.close();

        return fileDir.toString();
    } catch (Exception | OutOfMemoryError e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
    return null;
}

From source file:com.google.android.apps.dashclock.gmail.GmailExtension.java

@Override
protected void onUpdateData(int reason) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    String labelCanonical = sp.getString(PREF_LABEL, "i");
    Set<String> selectedAccounts = getSelectedAccounts();

    if ("i".equals(labelCanonical)) {
        labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_INBOX;
    } else if ("p".equals(labelCanonical)) {
        labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_PRIORITY_INBOX;
    }/*from www  . j a  v  a2s.  c o  m*/

    int unread = 0;
    List<Pair<String, Integer>> unreadPerAccount = new ArrayList<Pair<String, Integer>>();
    String lastUnreadLabelUri = null;

    for (String account : selectedAccounts) {
        Cursor cursor = tryOpenLabelsCursor(account);
        if (cursor == null || cursor.isAfterLast()) {
            LOGD(TAG, "No Gmail inbox information found for account.");
            if (cursor != null) {
                cursor.close();
            }
            continue;
        }

        int accountUnread = 0;

        while (cursor.moveToNext()) {
            int thisUnread = cursor.getInt(LabelsQuery.NUM_UNREAD_CONVERSATIONS);
            String thisCanonicalName = cursor.getString(LabelsQuery.CANONICAL_NAME);
            if (labelCanonical.equals(thisCanonicalName)) {
                accountUnread = thisUnread;
                if (thisUnread > 0) {
                    lastUnreadLabelUri = cursor.getString(LabelsQuery.URI);
                }
                break;
            } else if (!TextUtils.isEmpty(thisCanonicalName)
                    && thisCanonicalName.startsWith(SECTIONED_INBOX_CANONICAL_NAME_PREFIX)) {
                accountUnread += thisUnread;
                if (thisUnread > 0 && SECTIONED_INBOX_CANONICAL_NAME_PERSONAL.equals(thisCanonicalName)) {
                    lastUnreadLabelUri = cursor.getString(LabelsQuery.URI);
                }
            }
        }

        if (accountUnread > 0) {
            unreadPerAccount.add(new Pair<String, Integer>(account, accountUnread));
            unread += accountUnread;
        }

        cursor.close();
    }

    StringBuilder body = new StringBuilder();
    for (Pair<String, Integer> pair : unreadPerAccount) {
        if (pair.second == 0) {
            continue;
        }

        if (body.length() > 0) {
            body.append("\n");
        }
        body.append(pair.first).append(" (").append(pair.second).append(")");
    }

    Intent clickIntent = null;
    if (lastUnreadLabelUri != null) {
        try {
            clickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(lastUnreadLabelUri));
            if (getPackageManager().resolveActivity(clickIntent, 0) == null) {
                throw new IllegalStateException("Gmail can't open this label directly.");
            }
        } catch (Exception e) {
            LOGW(TAG, "Can't open Gmail label directly.", e);
            clickIntent = null;
        }
    }

    if (clickIntent == null) {
        clickIntent = new Intent(Intent.ACTION_MAIN).setPackage("com.google.android.gm")
                .addCategory(Intent.CATEGORY_LAUNCHER);
    }

    publishUpdate(new ExtensionData().visible(unread > 0).status(Integer.toString(unread))
            .expandedTitle(getResources().getQuantityString(R.plurals.gmail_title_template, unread, unread))
            .icon(R.drawable.ic_extension_gmail).expandedBody(body.toString()).clickIntent(clickIntent));
}

From source file:com.nextgis.ngm_clink_monitoring.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getBooleanExtra(FoclConstants.NO_SDCARD, false)) {

        YesNoDialog dialog = new YesNoDialog();
        dialog.setCancelable(false);/*from   www .  j a  v  a  2s  .c om*/
        dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning)
                .setMessage(getString(R.string.no_sdcard_exit_app)).setPositiveText(R.string.ok)
                .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() {
                    @Override
                    public void onPositiveClicked() {
                        // show Home screen
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        System.exit(0);
                    }
                }).show(getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "NoSdCard");
        return;
    }

    final GISApplication app = (GISApplication) getApplication();

    mGpsEventSource = app.getGpsEventSource();
    if (null != mGpsEventSource) {
        mGpsEventSource.addListener(this);
    }

    // initialize the default settings
    PreferenceManager.setDefaultValues(this, R.xml.preferences_general, false);

    mSyncStatusObserver = new SyncStatusObserver() {
        @Override
        public void onStatusChanged(int which) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Account account = app.getAccount();

                    if (null != account) {
                        mIsSyncing = AccountUtil.isSyncActive(account, FoclSettingsConstantsUI.AUTHORITY);
                        switchMenuView();
                    }
                }
            });
        }
    };

    setContentView(R.layout.activity_main);

    mMainToolbar = (Toolbar) findViewById(R.id.main_toolbar_cl);
    mMainToolbar.setTitle(""); // needed for screen rotation
    mMainToolbar.getBackground().setAlpha(255);
    setSupportActionBar(mMainToolbar);

    mBottomToolbar = (Toolbar) findViewById(R.id.bottom_toolbar_cl);
    mBottomToolbar.setContentInsetsAbsolute(0, 0);
    mBottomToolbar.getBackground().setAlpha(255);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Inflate a custom action bar that contains the "done" button
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View customActionBarView = inflater.inflate(R.layout.editor_custom_action_bar, null);

        mCustomToolbarTitle = (TextView) customActionBarView.findViewById(R.id.custom_toolbar_title);
        mCustomToolbarButton = (TextView) customActionBarView.findViewById(R.id.custom_toolbar_button);
        mCustomToolbarImage = (ImageView) customActionBarView.findViewById(R.id.custom_toolbar_image);

        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(customActionBarView);
    }

    // TODO: remove it
    //        FragmentManager fm = getSupportFragmentManager();
    //        mStatusBarFragment =
    //                (StatusBarFragment) fm.findFragmentByTag(FoclConstants.FRAGMENT_STATUS_BAR);
    //        if (null == mStatusBarFragment) {
    //            mStatusBarFragment = new StatusBarFragment();
    //            FragmentTransaction ft = fm.beginTransaction();
    //            ft.replace(
    //                    R.id.status_bar_fragment, mStatusBarFragment,
    //                    FoclConstants.FRAGMENT_STATUS_BAR);
    //            ft.hide(mStatusBarFragment);
    //            ft.commit();
    //        }

    if (null == savedInstanceState) {
        if (!app.hasAccount()) {
            mViewState = VIEW_STATE_LOGIN;
        } else if (null == app.getFoclProject()) {
            mViewState = VIEW_STATE_1ST_SYNC;
        } else {
            mViewState = VIEW_STATE_OBJECTS;
        }
    } else {
        if (savedInstanceState.containsKey(FoclConstants.VIEW_STATE)) {
            mViewState = savedInstanceState.getInt(FoclConstants.VIEW_STATE);
        }
    }

    setActivityView();

    // workaround for YesNoDialog destroying by the screen rotation
    FragmentManager fm = getSupportFragmentManager();
    Fragment fr = fm.findFragmentByTag(FoclConstants.FRAGMENT_YES_NO_DIALOG + "CancelObjectCreating");
    if (null != fr) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.remove(fr);
        ft.commit();
    }
}

From source file:com.farmerbb.taskbar.fragment.FreeformModeFragment.java

@TargetApi(Build.VERSION_CODES.N)
@Override// w w  w . jav a  2s  . c om
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());

    switch (p.getKey()) {
    case "freeform_hack":
        if (((CheckBoxPreference) p).isChecked()) {
            if (!U.hasFreeformSupport(getActivity())) {
                ((CheckBoxPreference) p).setChecked(false);

                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(R.string.freeform_dialog_title).setMessage(R.string.freeform_dialog_message)
                        .setPositiveButton(R.string.action_developer_options, (dialogInterface, i) -> {
                            showReminderToast = true;

                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
                            try {
                                startActivity(intent);
                                U.showToastLong(getActivity(), R.string.enable_force_activities_resizable);
                            } catch (ActivityNotFoundException e) {
                                intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
                                try {
                                    startActivity(intent);
                                    U.showToastLong(getActivity(), R.string.enable_developer_options);
                                } catch (ActivityNotFoundException e2) {
                                    /* Gracefully fail */ }
                            }
                        });

                AlertDialog dialog = builder.create();
                dialog.show();
                dialog.setCancelable(false);
            }

            if (pref.getBoolean("taskbar_active", false) && getActivity().isInMultiWindowMode()
                    && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(getActivity(), false, false);
            }
        } else {
            LocalBroadcastManager.getInstance(getActivity())
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
            LocalBroadcastManager.getInstance(getActivity())
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART"));
        }

        break;
    case "freeform_mode_help":
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(View.inflate(getActivity(), R.layout.freeform_help_dialog, null))
                .setTitle(R.string.freeform_help_dialog_title).setPositiveButton(R.string.action_close, null);

        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    case "add_shortcut":
        Intent intent = U.getShortcutIntent(getActivity());
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        intent.putExtra("duplicate", false);

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

        intent.setPackage(defaultLauncher.activityInfo.packageName);
        getActivity().sendBroadcast(intent);

        U.showToast(getActivity(), R.string.shortcut_created);
        break;
    case "window_size":
        if (U.isOPreview()) {
            U.showToast(getActivity(), R.string.window_sizes_not_available);
        }

        break;
    }

    return true;
}

From source file:com.cryart.sabbathschool.ui.activity.SSMainActivity.java

@Override
public void onBackPressed() {
    if (_SSDrawerLayout.isDrawerOpen(Gravity.START)) {
        _SSDrawerLayout.closeDrawer(Gravity.START);
    } else {/*from w  w  w .j a v a2s  . c  om*/
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}