FileDocCategorySizeDatePackage
VersionDialog.javaAPI DocAndroid 5.1 API3110Thu Mar 12 22:22:44 GMT 2015com.google.android.test.shared_library

VersionDialog

public class VersionDialog extends android.app.DialogFragment
This is the dialog we show when the library's version is older than the version the app needs.

Fields Summary
Constructors Summary
Methods Summary
public android.app.DialogonCreateDialog(android.os.Bundle savedInstanceState)

        final Activity activity = getActivity();

        // Need to use our library's resources for showing the dialog.
        final Context context;
        try {
            context = activity.createPackageContext(SharedLibraryMain.LIBRARY_PACKAGE, 0);
        } catch (PackageManager.NameNotFoundException e) {
            throw new IllegalStateException("Can't find my package!", e);
        }

        final Resources res = context.getResources();
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(res.getText(R.string.upgrade_title));
        builder.setMessage(res.getString(R.string.upgrade_body,
                activity.getApplicationInfo().loadLabel(activity.getPackageManager()),
                context.getApplicationInfo().loadLabel(context.getPackageManager())));
        builder.setPositiveButton(res.getText(R.string.upgrade_button),
                new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Launch play store into the details of our app.
                        try {
                            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id="
                                            + SharedLibraryMain.LIBRARY_PACKAGE)));
                        } catch (android.content.ActivityNotFoundException anfe) {
                            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://play.google.com/store/apps/details?id="
                                            + SharedLibraryMain.LIBRARY_PACKAGE)));
                        }
                    }
                });
        return builder.create();