Java Code Examples for com.facebook.react.bridge.WritableMap#putString()

The following examples show how to use com.facebook.react.bridge.WritableMap#putString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File:    From react-native-eval with MIT License 6 votes vote down vote up
 * Marshalls a function call to the javascript layer, via our NativeModule.
 * @param context The context needed to execute this in.
 * @param name The function to execute. e.g. "Math.Pow"
 * @param args The arguments to pass to the function, or null.
 * @param cb The completion callback for the result, or null.
 * @param event The name of the event that our NativeModule is listening for.
private static void callFunction(ReactContext context, String name, @Nullable Object[] args, @Nullable  EvaluatorCallback cb, String event) {
    String callId = UUID.randomUUID().toString();

    if (null != cb) {
        callbacks.put(callId, cb);

    WritableArray arguments = args != null ? Arguments.fromJavaArgs(args) : Arguments.createArray();
    if (arguments.size() == 0) {

    WritableMap eventParams = Arguments.createMap();
    eventParams.putString("name", name);
    eventParams.putArray("args", arguments);
    eventParams.putString("callId", callId);

    // TODO: move to AppEventEmitter once App events are supported on android.
            .emit(event, eventParams);
Example 2
Source File:    From react-native-GPay with MIT License 6 votes vote down vote up
public void testShowBasicShareDialog() {
  final WritableMap content = new WritableNativeMap();
  content.putString("message", "Hello, ReactNative!");
  final WritableMap options = new WritableNativeMap();

  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
  ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);

  getTestModule().showShareDialog(content, options);


  assertEquals(1, monitor.getHits());
  assertEquals(1, mRecordingModule.getOpened());
  assertEquals(0, mRecordingModule.getErrors());

Example 3
Source File:    From react-native-barcode with MIT License 6 votes vote down vote up
public ReadableMap decodeRGBBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
    BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
    WritableMap result = null;
    try {
        Result decodeResult = mReader.decode(bBitmap, mHints);
        result = Arguments.createMap();
        result.putInt("format", symbolToFormat(decodeResult.getBarcodeFormat()));
        result.putString("content", decodeResult.getText());
    } catch (NotFoundException ignored) {
    return result;
Example 4
Source File:    From react-native-telephony with MIT License 6 votes vote down vote up
public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) {
    WritableMap map = Arguments.createMap();
    map.putInt("cdmaDbm", signalStrength.getCdmaDbm());
    map.putInt("cdmaEcio()", signalStrength.getCdmaEcio());
    map.putInt("evdoDbm", signalStrength.getEvdoDbm());
    map.putInt("evdoEcio", signalStrength.getEvdoEcio());
    map.putInt("evdoSnr", signalStrength.getEvdoSnr());
    map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
    map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength());
    map.putBoolean("gsm", signalStrength.isGsm());

    WritableMap result = Arguments.createMap();
    result.putString("type", "LISTEN_SIGNAL_STRENGTHS");
    result.putMap("data", map);

    sendEvent(PHONE_STATE_LISTENER, result);
Example 5
Source File:    From imsdk-android with MIT License 6 votes vote down vote up
public void search(
        String key,
        int length,
        int start,
        String groupId,
        Promise promise) {

    WritableMap map = Arguments.createMap();
    map.putBoolean("is_ok", true);

    try {
        List ret = NativeApi.localSearch(key, start, length, groupId);

        String jsonStr =  JsonUtils.getGson().toJson(ret);
        map.putString("data", jsonStr);
    } catch (Exception e) {
        //map.putBoolean("is_ok", false);
        //map.putString("errorMsg", e.toString());
        promise.reject("500", e.toString(), e);
Example 6
Source File:    From react-native-fcm with MIT License 6 votes vote down vote up
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();

    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key =;
        Object value = jsonObject.get(key);
        if (value instanceof JSONObject) {
            map.putMap(key, convertJsonToMap((JSONObject) value));
        } else if (value instanceof  JSONArray) {
            map.putArray(key, convertJsonToArray((JSONArray) value));
        } else if (value instanceof  Boolean) {
            map.putBoolean(key, (Boolean) value);
        } else if (value instanceof  Integer) {
            map.putInt(key, (Integer) value);
        } else if (value instanceof  Double) {
            map.putDouble(key, (Double) value);
        } else if (value instanceof String)  {
            map.putString(key, (String) value);
        } else {
            map.putString(key, value.toString());
    return map;
Example 7
Source File:    From react-native-video with MIT License 6 votes vote down vote up
private WritableArray getTextTrackInfo() {
    WritableArray textTracks = Arguments.createArray();

    MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo();
    int index = getTrackRendererIndex(C.TRACK_TYPE_TEXT);
    if (info == null || index == C.INDEX_UNSET) {
        return textTracks;

    TrackGroupArray groups = info.getTrackGroups(index);
    for (int i = 0; i < groups.length; ++i) {
         Format format = groups.get(i).getFormat(0);
         WritableMap textTrack = Arguments.createMap();
         textTrack.putInt("index", i);
         textTrack.putString("title", != null ? : "");
         textTrack.putString("type", format.sampleMimeType);
         textTrack.putString("language", format.language != null ? format.language : "");
    return textTracks;
Example 8
Source File:    From react-native-google-nearby-connection with MIT License 5 votes vote down vote up
public void onReceive(Context context, Intent intent) {
	if (getReactApplicationContext().hasActiveCatalystInstance()) {
		String endpointId = intent.getStringExtra("endpointId");
		String endpointName = intent.getStringExtra("endpointName");
		String serviceId = intent.getStringExtra("serviceId");

		WritableMap out = Arguments.createMap();
		out.putString("endpointId", endpointId);
		out.putString("endpointName", endpointName);
		out.putString("serviceId", serviceId);
		sendEvent(getReactApplicationContext(), "connected_to_endpoint", out);
Example 9
Source File:    From react-native-quick-actions with MIT License 5 votes vote down vote up
WritableMap toWritableMap() {
    WritableMap map = Arguments.createMap();
    map.putString("type", type);
    map.putString("title", title);
    map.putString("icon", icon);
    map.putMap("userInfo", userInfo.toWritableMap());
    return map;
Example 10
Source File:    From react-native-flurry-sdk with Apache License 2.0 5 votes vote down vote up
private void sendEvent(EventType type, String key, boolean value) {
    WritableMap params = Arguments.createMap();
    params.putString("Type", type.getName());
    if (key != null) {
        params.putBoolean(key, value);

            .emit(FLURRY_CONFIG_EVENT, params);
Example 11
Source File:    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
public static WritableMap Message(Message message) {
    WritableMap map = Arguments.createMap();

    map.putString("sid", message.getSid());
    map.putInt("index", (int) message.getMessageIndex());
    map.putString("author", message.getAuthor());
    map.putString("body", message.getMessageBody());
    map.putString("timestamp", message.getTimeStamp());
    map.putMap("attributes", jsonToWritableMap(message.getAttributes()));
    return map;
Example 12
Source File:    From react-native-usbserial with MIT License 5 votes vote down vote up
public void getDeviceListAsync(Promise p) {

    try {
        UsbManager usbManager = getUsbManager();

        HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
        WritableArray deviceArray = Arguments.createArray();

        for (String key: usbDevices.keySet()) {
            UsbDevice device = usbDevices.get(key);
            WritableMap map = Arguments.createMap();

            map.putString("name", device.getDeviceName());
            map.putInt("deviceId", device.getDeviceId());
            map.putInt("productId", device.getProductId());
            map.putInt("vendorId", device.getVendorId());
            map.putString("deviceName", device.getDeviceName());


    } catch (Exception e) {
Example 13
Source File:    From react-native-tcp-socket with MIT License 5 votes vote down vote up
public void onData(Integer id, byte[] data) {
    WritableMap eventParams = Arguments.createMap();
    eventParams.putInt("id", id);
    eventParams.putString("data", Base64.encodeToString(data, Base64.NO_WRAP));

    sendEvent("data", eventParams);
Example 14
Source File:    From react-native-fitness with MIT License 5 votes vote down vote up
private void processCalories(DataSet dataSet, WritableArray map) {

        WritableMap caloryMap = Arguments.createMap();

        for (DataPoint dp : dataSet.getDataPoints()) {
            for(Field field : dp.getDataType().getFields()) {
                caloryMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
                caloryMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
                caloryMap.putDouble("quantity", dp.getValue(field).asFloat());
Example 15
Source File:    From react-native-sip with GNU General Public License v3.0 5 votes vote down vote up
private static WritableMap fromJsonObject(JsonObject object) {
    WritableMap result = new WritableNativeMap();

    for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
        Object value = fromJson(entry.getValue());

        if (value instanceof WritableMap) {
            result.putMap(entry.getKey(), (WritableMap) value);
        } else if (value instanceof WritableArray) {
            result.putArray(entry.getKey(), (WritableArray) value);
        } else if (value instanceof String) {
            result.putString(entry.getKey(), (String) value);
        } else if (value instanceof LazilyParsedNumber) {
            result.putInt(entry.getKey(), ((LazilyParsedNumber) value).intValue());
        } else if (value instanceof Integer) {
            result.putInt(entry.getKey(), (Integer) value);
        } else if (value instanceof Double) {
            result.putDouble(entry.getKey(), (Double) value);
        } else if (value instanceof Boolean) {
            result.putBoolean(entry.getKey(), (Boolean) value);
        } else {
            Log.d("ArgumentUtils", "Unknown type: " + value.getClass().getName());

    return result;
Example 16
Source File:    From react-native-firestack with MIT License 5 votes vote down vote up
public void deleteUser(final Callback callback) {
  FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

  if (user != null) {
      .addOnCompleteListener(new OnCompleteListener<Void>() {
        public void onComplete(@NonNull Task<Void> task) {
          if (task.isSuccessful()) {
            Log.d(TAG, "User account deleted");
            WritableMap resp = Arguments.createMap();
            resp.putString("status", "complete");
            resp.putString("msg", "User account deleted");
            callback.invoke(null, resp);
          } else {
            // userErrorCallback(task, callback);
      }).addOnFailureListener(new OnFailureListener() {
          public void onFailure(@NonNull Exception ex) {
            userExceptionCallback(ex, callback);
  } else {
    WritableMap err = Arguments.createMap();
    err.putInt("errorCode", NO_CURRENT_USER);
    err.putString("errorMessage", "No current user");
Example 17
Source File:    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
public void onError(ErrorInfo errorInfo) {
    WritableMap map = Arguments.createMap();
    map.putString("userInfo", errorInfo.toString());

    sendEvent("ipMessagingClient:errorReceived", map);
Example 18
Source File:    From opentok-react-native with MIT License 5 votes vote down vote up
public static WritableMap prepareStreamPropertyChangedEventData(String changedProperty, Boolean oldValue, Boolean newValue, Stream stream, Session session) {

        WritableMap streamPropertyEventData = Arguments.createMap();
        streamPropertyEventData.putString("changedProperty", changedProperty);
        streamPropertyEventData.putBoolean("oldValue", oldValue);
        streamPropertyEventData.putBoolean("newValue", newValue);
        streamPropertyEventData.putMap("stream", prepareJSStreamMap(stream, session));
        return streamPropertyEventData;
Example 19
Source File:    From react-native-telephony with MIT License 5 votes vote down vote up
public void phoneCallForwardingIndicatorUpdated(boolean cfi) {
    WritableMap map = Arguments.createMap();
    map.putBoolean("cfi", cfi);

    WritableMap result = Arguments.createMap();
    result.putString("type", "LISTEN_CALL_FORWARDING_INDICATOR");
    result.putMap("data", map);

    sendEvent(PHONE_STATE_LISTENER, result);
Example 20
Source File:    From ReactNativeDropdownAndroid with MIT License 4 votes vote down vote up
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("selected", getPosition());
    eventData.putString("value", getValue());
    return eventData;