Java tutorial
//package com.java2s; import android.app.Activity; import android.app.AlertDialog; public class Main { /** * 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(); } }