Example usage for android.content Intent getShortExtra

List of usage examples for android.content Intent getShortExtra

Introduction

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

Prototype

public short getShortExtra(String name, short defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:Main.java

public static short getShortExtra(Intent intent, String name, short defaultValue) {
    if (!hasIntent(intent) || !hasExtra(intent, name))
        return defaultValue;
    return intent.getShortExtra(name, defaultValue);
}

From source file:com.daon.identityx.uaf.UafClientUtils.java

/**
 * {@inheritDoc}//w w  w .  j a  v a 2 s .  c o m
 */
@Override
public String getUafClientResponse(FidoOperation fidoOpType, Intent resultIntent) {
    // Check response intent from UAF client for errors. If it's OK send the response message created by the client to the server.
    Log.d(LogUtils.TAG, "processClientResultIntent called.");
    UafClientLogUtils.logClientResultIntent(resultIntent, fidoOpType);
    short errorCode = resultIntent.getShortExtra("errorCode", (short) -1);
    if (errorCode != ErrorCode.NO_ERROR.getValue()) {
        throw new UafProcessingException(
                "FIDO Client Processing Error: " + ErrorCode.getByValue(errorCode).getDescription());
    } else {
        String intentType = resultIntent.getStringExtra("UAFIntentType");
        if (intentType != null) {
            switch (intentType) {
            case "UAF_OPERATION_RESULT":
                String fidoUafMessage = resultIntent.getStringExtra("message");
                if (fidoUafMessage != null) {
                    Gson gson = new Gson();
                    //UAFMessage uafMessage = gson.fromJson(fidoUafMessage, UAFMessage.class);
                    //String uafResponseJson = uafMessage.getUafProtocolMessage();
                    //return uafMessage.getUafProtocolMessage();
                    return fidoUafMessage;
                } else {
                    return null;
                }
            case "DISCOVER_RESULT":
                return resultIntent.getStringExtra("discoveryData");
            case "CHECK_POLICY_RESULT":
                Log.d(LogUtils.TAG, "checking policy result.");
                return null;
            default:
                throw new UafProcessingException("Unrecognised UAF client response intent type: " + intentType);
            }
        } else {
            throw new UafProcessingException("UAF client response intent is missing the UAFIntentType extra.");
        }
    }
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindIntentExtra(Object receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);//from   ww  w  .j  a va  2  s . co  m
        IntentExtra intentExtra = field.getAnnotation(IntentExtra.class);
        if (intentExtra != null) {
            try {
                Intent intent = null;
                if (receiver instanceof Activity) {
                    intent = ((Activity) receiver).getIntent();
                } else if (receiver instanceof Fragment) {
                    intent = ((Fragment) receiver).getActivity().getIntent();
                }
                if (intent != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000'));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, intent.getIntExtra(intentExtra.value(), 0));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0));
                    } else if (type == String.class) {
                        field.set(receiver, intent.getStringExtra(intentExtra.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, intent.getByteArrayExtra(intentExtra.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, intent.getCharArrayExtra(intentExtra.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, intent.getFloatArrayExtra(intentExtra.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, intent.getIntArrayExtra(intentExtra.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, intent.getLongArrayExtra(intentExtra.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, intent.getShortArrayExtra(intentExtra.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, intent.getStringArrayExtra(intentExtra.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, intent.getSerializableExtra(intentExtra.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, intent.getBundleExtra(intentExtra.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}