/** * Try to connect to the MMF app in the currently assigned {@link * com.mapmyfitness.android.mmfremote.AppPackage}. If this enum is null, this method will simply * return false. You can use {@link * #tryToConnectToMmfApp(com.mapmyfitness.android.mmfremote.AppPackage)} if you would like to pass * it one at the time you try to connect, or use {@link #getAppPackage()} to check if one is * present. * * @return */ public boolean tryToConnectToMmfApp() { if (!isAppConnected() && mAppPackage != null) { return mRemoteCommunication.onConnectionTried(mContext, mAppPackage.getIntentActionFilter()); } else { return true; } }
private static void reloadPackage() { packageMap.clear(); String packageDir = workSpaceDir; packageDir += "package"; File packageFolder = new File(packageDir); if (packageFolder.exists() && packageFolder.isDirectory()) { for (File ff : packageFolder.listFiles()) { if (ff.isFile() && !ff.isHidden()) { AppPackage pkg = new AppPackage(); String fileName = ff.getName(); pkg.id = (fileName); pkg.file = (ff.getAbsolutePath()); pkg.lastModifiedTime = new Date(ff.lastModified()); packageMap.put(pkg.id, pkg); } } } }
/** * Get the {@link com.mapmyfitness.android.mmfremote.AppInfo} for the app package passed. * * @param appPackage the app package which you want to check * @return and {@link com.mapmyfitness.android.mmfremote.AppInfo} with info on the app */ public AppInfo getAppInfo(AppPackage appPackage) { PackageManager pm = mContext.getPackageManager(); AppInfo appInfo; try { PackageInfo pi = pm.getPackageInfo(appPackage.toString(), PackageManager.GET_ACTIVITIES); appInfo = new AppInfo(appPackage, true, pi.versionCode); } catch (PackageManager.NameNotFoundException e) { // app is not install appInfo = new AppInfo(appPackage, false, 0); } return appInfo; }
/** * This method tries to check the state of an app represented by an {@link * com.mapmyfitness.android.mmfremote.AppPackage}. Remember, like {@link #requestAppState()}, it * no {@link com.mapmyfitness.android.mmfremote.RemoteCommandListener} is set, you will not * receive any callbacks on the state of the app. These are the steps taken in this method: * * <ol> * <li>If the app is connected, we check if the {@link * com.mapmyfitness.android.mmfremote.AppPackage} in the parameter is equal to the one set * in this class. In that case, we ask the MMF app to send us the state. If the package in * the parameter is different than the one held by this page, we check to see if it is * installed or just not connected. * <li>If the app is not connected, we check if the package is installed, if so, we return * {@link com.mapmyfitness.android.mmfremote.AppState#APP_NOT_CONNECTED} * <li>If none of the above qualify, we return {@link * com.mapmyfitness.android.mmfremote.AppState#APP_NOT_INSTALLED} * </ol> * * You can also use the {@link #getAppInfo(com.mapmyfitness.android.mmfremote.AppPackage)} method * and the returned {@link com.mapmyfitness.android.mmfremote.AppInfo} object to see if the app is * installed or not. * * @param appPackage */ public void requestAppState(AppPackage appPackage) { if (isAppConnected()) { if (mAppPackage != null && mAppPackage.equals(appPackage)) { mRemoteCommunication.getCurrentStateCommand(); } else if (mAppPackage != null && getAppInfo(appPackage).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 (getAppInfo(appPackage).isInstalled()) { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_CONNECTED); } } else { if (mRemoteCommunication.getCommandListener() != null) { mRemoteCommunication.getCommandListener().onAppStateEvent(AppState.APP_NOT_INSTALLED); } } }