Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Created February 2, 2017 16:57
Show Gist options
  • Select an option

  • Save AppWerft/87280abe051b2ba273670f01ef2d71f2 to your computer and use it in GitHub Desktop.

Select an option

Save AppWerft/87280abe051b2ba273670f01ef2d71f2 to your computer and use it in GitHub Desktop.
package com.linkedin.platform.internals;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
public class AppStore {
final static String LCAT = "LinkedIn 👥";
public static void goAppStore(final Activity activity, boolean showDialog,
String[] alertTexts) {
if (!showDialog) {
goToAppStore(activity);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
Log.d(LCAT, "try to go appstore ");
builder.setMessage(alertTexts[0]).setTitle(alertTexts[1]);
builder.setPositiveButton(alertTexts[2],
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
goToAppStore(activity);
dialogInterface.dismiss();
}
});
builder.setNegativeButton(alertTexts[3],
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.create().show();
}
private static void goToAppStore(final Activity activity) {
SupportedAppStore appStore = SupportedAppStore.fromDeviceManufacturer();
Log.d(LCAT, "try to go appstore " + appStore.toString());
String appStoreUri = appStore.getAppStoreUri();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(appStoreUri));
try {
activity.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
// should not happen
}
}
private static enum SupportedAppStore {
amazonAppstore("amazon", "amzn://apps/android?p=com.linkedin.android"), googlePlay(
"google", "market://details?id=com.linkedin.android"), samsungApps(
"samsung", "samsungapps://ProductDetail/com.linkedin.android");
private final String deviceManufacturer;
private final String appStoreUri;
private SupportedAppStore(String deviceManufacturer, String appStoreUri) {
this.deviceManufacturer = deviceManufacturer;
this.appStoreUri = appStoreUri;
}
public String getDeviceManufacturer() {
return deviceManufacturer;
}
public String getAppStoreUri() {
return appStoreUri;
}
public static SupportedAppStore fromDeviceManufacturer() {
for (SupportedAppStore appStore : values()) {
if (appStore.getDeviceManufacturer().equalsIgnoreCase(
Build.MANUFACTURER)) {
return appStore;
}
}
// return google play by default
return googlePlay;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment