Last active
April 26, 2019 18:30
-
-
Save drewlarsen/1c55254464168ed1efb6a528232087e5 to your computer and use it in GitHub Desktop.
How to Open SugarWOD from another Android App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from: | |
// https://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent/7596063#7596063 | |
/** Open SugarWOD. | |
* @param context current Context, like Activity, App, or Service | |
* @return true if likely successful, false if unsuccessful | |
*/ | |
public static boolean openSugarWOD(Context context) { | |
String packageName = "com.flatironssoftware.sugarwod"; | |
PackageManager manager = context.getPackageManager(); | |
try { | |
Intent i = manager.getLaunchIntentForPackage(packageName); | |
if (i == null) { | |
return false; | |
} | |
i.addCategory(Intent.CATEGORY_LAUNCHER); | |
context.startActivity(i); | |
return true; | |
} catch (ActivityNotFoundException e) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment