Skip to content

Instantly share code, notes, and snippets.

@phil-monroe
Created November 19, 2019 18:48
Show Gist options
  • Save phil-monroe/46f4b0e40b57ed1098034adc335cf742 to your computer and use it in GitHub Desktop.
Save phil-monroe/46f4b0e40b57ed1098034adc335cf742 to your computer and use it in GitHub Desktop.
public class AMIUtils {
static String SELL_WITH_AMI_PACKAGE = "com.maven_labs.maven";
public static void openSellWithAMI(Context context) {
if(isPackageInstalled(SELL_WITH_AMI_PACKAGE, context.getPackageManager())) {
openLink("mavenami://", context);
} else {
try {
openLink("market://details?id=" + SELL_WITH_AMI_PACKAGE, context);
} catch (android.content.ActivityNotFoundException anfe) {
openLink("https://play.google.com/store/apps/details?id=" + SELL_WITH_AMI_PACKAGE, context);
}
}
}
static void openLink(String link, Context context) {
Log.i("AMIUtils", "Opening link: " + link);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
static boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
return packageManager.getApplicationInfo(packageName, 0).enabled;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment