/** * Get a list of all MMF apps installed. This will return an empty {@link java.util.ArrayList< * com.mapmyfitness.android.mmfremote.AppInfo >} object. Then you would know non of our supported * apps are installed in the phone. * * @return array of type {@link com.mapmyfitness.android.mmfremote.AppInfo} with info on apps * installed */ public ArrayList<AppInfo> findInstalledApps() { AppInfo appInfo; ArrayList<AppInfo> appInfoList = new ArrayList<AppInfo>(); // try each of the 10 apps appInfo = getAppInfo(AppPackage.MAPMYFITNESS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYFITNESSPLUS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYRUN); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYRUNPLUS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYRIDE); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYRIDEPLUS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYHIKE); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYHIKEPLUS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYWALK); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } appInfo = getAppInfo(AppPackage.MAPMYWALKPLUS); if (appInfo.isInstalled()) { appInfoList.add(appInfo); } return appInfoList; }
/** * This method is a bit dangerous and it makes some assumptions. Ideally, if we are connected to * an MMF app we would just ask it for the app state and get that state in the {@link * com.mapmyfitness.android.mmfremote.RemoteCommandListener#onAppStateEvent(com.mapmyfitness.android.mmfremote.AppState)} * callback. However, if we are not connected to an MMF app we can't be 100% sure which MMF app * you intend to check for if the {@link com.mapmyfitness.android.mmfremote.AppPackage} is not set * in this class. Lastly, if no {@link com.mapmyfitness.android.mmfremote.RemoteCommandListener} * is set, you will not receieve a callback. In that case the method will appear to fail silently. * These are steps we take: * * <ol> * <li>If MMF app is connected to SDK: ask it the current state and listen for it in the {@link * com.mapmyfitness.android.mmfremote.RemoteCommandListener#onAppStateEvent(com.mapmyfitness.android.mmfremote.AppState)} * callback. Remember if no callback is set, you will not get any feedback about the state * of the app. * <li>If we have an {@link com.mapmyfitness.android.mmfremote.AppPackage} set, then check it to * see if app is installed. If the app is installed we will send a callback with {@link * com.mapmyfitness.android.mmfremote.AppState#APP_NOT_CONNECTED}. If the app is not * installed we will send a callback with {@link * com.mapmyfitness.android.mmfremote.AppState#APP_NOT_INSTALLED}. * <li>If the {@link com.mapmyfitness.android.mmfremote.AppPackage} is not set, we are not sure * which one of the 10 apps you are requesting. In that case, we will use {@link * #findInstalledApps()} to see if any of our supported apps are installed. If at least one * of them is installed we return {@link * com.mapmyfitness.android.mmfremote.AppState#APP_NOT_CONNECTED}. If none of our supported * are installed, we return {@link * com.mapmyfitness.android.mmfremote.AppState#APP_NOT_INSTALLED}. * </ol> * * A better way to get an app's state is to use {@link * #requestAppState(com.mapmyfitness.android.mmfremote.AppPackage)} passing it the {@link * com.mapmyfitness.android.mmfremote.AppPackage} you are interested in. That will be more precise * by narrowing down the options to one app. */ public void requestAppState() { if (isAppConnected()) { mRemoteCommunication.getCurrentStateCommand(); } else if (mAppPackage != null) { AppInfo appInfo = getAppInfo(mAppPackage); if (appInfo.isInstalled()) { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_CONNECTED); } } else { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_INSTALLED); } } } else { if (findInstalledApps().size() > 0) { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_CONNECTED); } } else { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_INSTALLED); } } } }