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:com.farmerbb.taskbar.service.TaskbarService.java

private boolean hasLauncherIntent(String packageName) {
    Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
    intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
    intentToResolve.setPackage(packageName);

    List<ResolveInfo> ris = getPackageManager().queryIntentActivities(intentToResolve, 0);
    return ris != null && ris.size() > 0;
}

From source file:co.taqat.call.LinphoneActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (!LinphoneService.isReady()) {
        startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
    }//from w ww.j  ava 2s.co m

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
        lc.addListener(mListener);
    }

    if (isTablet()) {
        // Prevent fragmentContainer2 to be visible when rotating the device
        LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
        if (currentFragment == FragmentsAvailable.DIALER || currentFragment == FragmentsAvailable.ABOUT
                || currentFragment == FragmentsAvailable.SETTINGS
                || currentFragment == FragmentsAvailable.ACCOUNT_SETTINGS) {
            ll.setVisibility(View.GONE);
        }
    }

    refreshAccounts();

    if (getResources().getBoolean(R.bool.enable_in_app_purchase)) {
        isTrialAccount();
    }

    updateMissedChatCount();
    if (LinphonePreferences.instance().isFriendlistsubscriptionEnabled()
            && LinphoneManager.getLc().getDefaultProxyConfig() != null) {
        LinphoneManager.getInstance().subscribeFriendList(true);
    } else {
        LinphoneManager.getInstance().subscribeFriendList(false);
    }

    displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());

    LinphoneManager.getInstance().changeStatusToOnline();

    if (getIntent().getIntExtra("PreviousActivity", 0) != CALL_ACTIVITY && !doNotGoToCallActivity) {
        if (LinphoneManager.getLc().getCalls().length > 0) {
            LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
            LinphoneCall.State callState = call.getState();

            if (callState == State.IncomingReceived) {
                startActivity(new Intent(this, CallIncomingActivity.class));
            } else if (callState == State.OutgoingInit || callState == State.OutgoingProgress
                    || callState == State.OutgoingRinging) {
                startActivity(new Intent(this, CallOutgoingActivity.class));
            } else {
                startIncallActivity(call);
            }
        }
    }
    doNotGoToCallActivity = false;
}

From source file:com.amaze.filemanager.fragments.Main.java

private void addShortcut(Layoutelements path) {
    //Adding shortcut for MainActivity
    //on Home screen
    Intent shortcutIntent = new Intent(getActivity().getApplicationContext(), MainActivity.class);
    shortcutIntent.putExtra("path", path.getDesc());
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, new File(path.getDesc()).getName());

    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getActivity(), R.mipmap.ic_launcher));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getActivity().sendBroadcast(addIntent);
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();//from   ww w  .j a v a  2  s.  c o m

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

        Runnable processIntent = new Runnable() {
            public void run() {
                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();
                if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()
                        && openFolder == null) {
                    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 AllApps to its initial state
                if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
                    mAppsCustomizeTabHost.reset();
                }
            }
        };

        if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
            // Delay processing of the intent to allow the status bar animation to finish
            // first in order to avoid janky animations.
            mWorkspace.postDelayed(processIntent, 350);
        } else {
            // Process the intent immediately.
            processIntent.run();
        }

    }
}

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

private static void applyChange(Activity context) {
    context.finish();//from  w  ww  . ja v  a 2s . co  m
    context.startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .addCategory(Intent.CATEGORY_DEFAULT).addCategory(Intent.CATEGORY_HOME));
}

From source file:org.linphone.LinphoneActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (currentFragment == FragmentsAvailable.SETTINGS) {
            //dialer.setVisibility(View.GONE);
            settings.setVisibility(View.VISIBLE);
            //mCall.setVisibility(View.VISIBLE);
        }/*from   w  ww . j  av a2 s .  c  o m*/
        if (currentFragment == FragmentsAvailable.DIALER || currentFragment == FragmentsAvailable.CONTACTS
                || currentFragment == FragmentsAvailable.HISTORY
                || currentFragment == FragmentsAvailable.CHATLIST
                || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
                || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS) {
            boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
            if (!isBackgroundModeActive) {
                stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
                finish();
            } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                return true;
            }
        } else {
            if (isTablet()) {
                if (currentFragment == FragmentsAvailable.SETTINGS) {
                    updateAnimationsState();
                }
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {
        if (event.getRepeatCount() < 1) {
            statusFragment.openOrCloseStatusBar(true);
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.negaheno.android.NotificationsController.java

public static String getLauncherClassName(Context context) {
    try {/*  www .  j  av a  2 s. c  om*/
        PackageManager pm = context.getPackageManager();

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

        List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                return resolveInfo.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
    return null;
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

private static String getLauncherClassName(Context context) {
    try {//from www .java 2  s  . c om
        PackageManager pm = context.getPackageManager();

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

        List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                return resolveInfo.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
    return null;
}

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

private static void changeDefaultLauncher(Context context) {
    PackageManager packageManager = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, FakeActivity.class);
    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    Intent selector = new Intent(Intent.ACTION_MAIN);
    selector.addCategory(Intent.CATEGORY_HOME);
    selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(selector);/*from   w  w  w. java  2 s . com*/

    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
            PackageManager.DONT_KILL_APP);
}

From source file:com.aliyun.homeshell.Folder.java

public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, boolean success) {
    mDropAccepted = success;/*  w  w w . j  a v a 2  s  .  c om*/
    Log.d(TAG,
            "sxsexe---------> onDropCompleted dragInfo " + d.dragInfo + " success " + success
                    + " mDeleteFolderOnDropCompleted " + mDeleteFolderOnDropCompleted
                    + " mItemAddedBackToSelfViaIcon " + mItemAddedBackToSelfViaIcon + " item count "
                    + getItemCount() + " mHasDirtyData " + mHasDirtyData);
    /*YUNOS BEGIN*/
    //##module(component name)
    //##date:2014/03/28 ##author:jun.dongj@alibaba-inc.com##BugID:105531
    //there is a cellayout outline when drag icon in folder, otherwise, hide it
    showDragOutline(false);
    /*YUNOS END*/
    mShortcutInfoCache = (ShortcutInfo) d.dragInfo;
    mLauncher.setCurrentFolder(this);
    if (success) {
        if (target instanceof DeleteDropTarget
                && mShortcutInfoCache.itemType == Favorites.ITEM_TYPE_APPLICATION) {
            /* YUNOS BEGIN PB*/
            //##modules(HomeShell): ##author:guoshuai.lgs
            //##BugID:(5221896) ##date:2014/09/03
            //##decrpition: support mainmenu feature, cancel drop feature, page management feature, and so on
            if (!LauncherApplication.isMainmenuMode()) {
                //go to uninstall or remove, 
                Log.d(TAG, "sxsexe---------> onDropCompleted do not need to replaceFolderWithFinalItem");
                mHasDirtyData = true;

                /*YUNOS BEGIN*/
                //##date:2014/01/18 ##author:hao.liuhaolh ##BugID:83464
                //app icon remove issue in folder
                if ((mShortcutInfoCache.intent != null) && (mShortcutInfoCache.intent.getComponent() != null)
                        && (mShortcutInfoCache.intent.getComponent().getPackageName() != null)) {
                    boolean storgeMount = Environment.getExternalStorageState()
                            .equals(Environment.MEDIA_MOUNTED);

                    String packageName = mShortcutInfoCache.intent.getComponent().getPackageName();
                    final PackageManager packageManager = ((Context) mLauncher).getPackageManager();

                    final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
                    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                    mainIntent.setPackage(packageName);
                    final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
                    if ((apps == null || apps.size() == 0) && (storgeMount == true)) {
                        Log.d(TAG, "no app info, so it need to be cleaned");
                        mHasDirtyData = false;
                    }
                }
            }
            /*YUNOS END PB*/
            /*YUNOS END*/
        }
        /*YUNOS BEGIN*/
        //##date:2014/7/2 ##author:yangshan.ys##BugID:134407
        //if the target is workspace or hotseat when drag or fling icon ,call this method
        mDeleteFolderOnDropCompleted = mInfo.count() <= 1;
        if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon
                && !(target instanceof DeleteDropTarget)) {
            /*YUNOS END*/
            if (!mHasDirtyData) {
                //drag to workspace or hotseat
                replaceFolderWithFinalItem();
                this.setNeedReplaceFolderWithFinalItemFlase();
            }
        }
    } else {
        Log.d(TAG, "sxsexe---------> onDropCompleted drag failed need to get the item back ");
        /*YUNOS BEGIN*/
        //##date:2014/06/18 ##author:guoshuai.lgs ##BugID:
        //support the folder feature in mainmenu
        if (LauncherApplication.isMainmenuMode() && (mInfo.isMainmenuFolder())) {
            // Exit spring loaded mode if we have not successfully dropped or have not handled the
            // drop in Workspace
            //Delete the dragview
            d.deferDragViewCleanupPostAnimation = false;
            mLauncher.exitSpringLoadedDragMode();
        } else {
            // The drag failed, we need to return the item to the folder
            mFolderIcon.onDrop(d);
        }
        /*YUNOS END*/

        // We're going to trigger a "closeFolder" which may occur before this item has
        // been added back to the folder -- this could cause the folder to be deleted
        if (mOnExitAlarm.alarmPending()) {
            mSuppressFolderDeletion = true;
        }
    }

    if (target != this) {
        if (mOnExitAlarm.alarmPending()) {
            mOnExitAlarm.cancelAlarm();
            completeDragExit();
        }
    }
    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragInfo = null;
    mCurrentDragView = null;
    mSuppressOnAdd = false;
    /* YUNOS BEGIN */
    // ##date:2014/07/04 ##author:yangshan.ys##BugID:135044
    // prevent the position of editfoldericon moving in folder
    if (target == this && mInfo.isEditFolderInContents() && mEditFolderTempView != null) {
        int childId = mEditFolderTempView.getId();
        CellLayout.LayoutParams params = (CellLayout.LayoutParams) mEditFolderTempView.getLayoutParams();
        mContentList.get(mInfo.getmEditFolderShortcutInfo().screen).addViewToCellLayout(mEditFolderTempView, -1,
                childId, params, true);
        mEditFolderHidden = false;
    }
    /* YUNOS END */
    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    /*YUNOS BEGIN*/
    //##date:2014/06/10 ##author:guoshuai.lgs ##BugID:
    //support the folder feature in mainmenu
    if (mInfo.isMainmenuFolder() && (LauncherApplication.isMainmenuMode())) {
        // TODO: do nothing?
    } else {
        updateItemLocationsInDatabase();
    }
    /*YUNOS END*/
    mLauncher.getWorkspace().cleanDragInfoFromFolder();
    mLauncher.getWorkspace().checkAndRemoveEmptyCell();
}