Example usage for android.content Intent EXTRA_REASON

List of usage examples for android.content Intent EXTRA_REASON

Introduction

In this page you can find the example usage for android.content Intent EXTRA_REASON.

Prototype

String EXTRA_REASON

To view the source code for android.content Intent EXTRA_REASON.

Click Source Link

Document

Intent extra: the reason that the operation associated with this intent is being performed.

Usage

From source file:com.android.managedprovisioning.DeviceOwnerProvisioningActivity.java

private void error(int dialogMessage, boolean resetRequired) {
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this).setTitle(R.string.provisioning_error_title)
            .setMessage(dialogMessage).setCancelable(false);
    if (resetRequired) {
        alertBuilder.setPositiveButton(R.string.device_owner_error_reset,
                new DialogInterface.OnClickListener() {
                    @Override/* w w  w  . j  a va  2  s. c  om*/
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();

                        // Factory reset the device.
                        Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                        intent.putExtra(Intent.EXTRA_REASON, "DeviceOwnerProvisioningActivity.error()");
                        sendBroadcast(intent);
                        stopService(new Intent(DeviceOwnerProvisioningActivity.this,
                                DeviceOwnerProvisioningService.class));
                        setResult(RESULT_CANCELED);
                        finish();
                    }
                });
    } else {
        alertBuilder.setPositiveButton(R.string.device_owner_error_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();

                // Close activity.
                stopService(
                        new Intent(DeviceOwnerProvisioningActivity.this, DeviceOwnerProvisioningService.class));
                setResult(RESULT_CANCELED);
                finish();
            }
        });
    }
    alertBuilder.show();
}