Android APK Installation Check verifySampleSetup(Activity activity, int... resIds)

Here you can find the source of verifySampleSetup(Activity activity, int... resIds)

Description

For use in sample code only.

Parameter

Parameter Description
resIds the resource IDs to check for placeholders

Return

true if sample is set up correctly; false otherwise.

Declaration

public static boolean verifySampleSetup(Activity activity,
        int... resIds) 

Method Source Code

//package com.java2s;
import android.app.Activity;
import android.app.AlertDialog;

public class Main {
    /**/*from  ww w .  java  2 s  .c o m*/
     * For use in sample code only. Checks if the sample was set up correctly,
     * including changing the package name to a non-Google package name and
     * replacing the placeholder IDs. Shows alert dialogs to notify about problems.
     * DO NOT call this method from a production app, it's meant only for samples!
     * @param resIds the resource IDs to check for placeholders
     * @return true if sample is set up correctly; false otherwise.
     */
    public static boolean verifySampleSetup(Activity activity,
            int... resIds) {
        StringBuilder problems = new StringBuilder();
        boolean problemFound = false;
        problems.append("The following set up problems were found:\n\n");

        // Did the developer forget to change the package name?
        if (activity.getPackageName()
                .startsWith("com.google.example.games")) {
            problemFound = true;
            problems.append(
                    "- Package name cannot be com.google.*. You need to change the "
                            + "sample's package name to your own package.")
                    .append("\n");
        }

        for (int i : resIds) {
            if (activity.getString(i).toLowerCase().contains("replaceme")) {
                problemFound = true;
                problems.append(
                        "- You must replace all "
                                + "placeholder IDs in the ids.xml file by your project's IDs.")
                        .append("\n");
                break;
            }
        }

        if (problemFound) {
            problems.append("\n\nThese problems may prevent the app from working properly.");
            showAlert(activity, problems.toString());
            return false;
        }

        return true;
    }

    /**
     * Show an {@link android.app.AlertDialog} with an 'OK' button and a message.
     *
     * @param activity the Activity in which the Dialog should be displayed.
     * @param message the message to display in the Dialog.
     */
    public static void showAlert(Activity activity, String message) {
        (new AlertDialog.Builder(activity)).setMessage(message)
                .setNeutralButton(android.R.string.ok, null).create()
                .show();
    }
}

Related

  1. isAppInstalled(Context ctx, String uri)
  2. isApkInstalled(Context context, String packageName)
  3. installApk(Context context, File file)
  4. installApk(Context context, File file)
  5. uninstallApk(Context context, String packageName)
  6. installWatchapp(final Activity parent, final String pbwFilename, final String appstoreUid)