Java Code Examples for com.facebook.react.bridge.WritableNativeMap

The following examples show how to use com.facebook.react.bridge.WritableNativeMap. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void resolveImage(final File imageFile, final Promise promise, boolean addToMediaStore) {
    final WritableMap response = new WritableNativeMap();
    response.putString("path", Uri.fromFile(imageFile).toString());

    if(addToMediaStore) {
        // borrowed from react-native CameraRollManager, it finds and returns the 'internal'
        // representation of the image uri that was just saved.
        // e.g. content://media/external/images/media/123
        MediaScannerConnection.scanFile(
                _reactContext,
                new String[]{imageFile.getAbsolutePath()},
                null,
                new MediaScannerConnection.OnScanCompletedListener() {
                    @Override
                    public void onScanCompleted(String path, Uri uri) {
                        if (uri != null) {
                            response.putString("mediaUri", uri.toString());
                        }

                        promise.resolve(response);
                    }
                });
    } else {
        promise.resolve(response);
    }
}
 
Example 2
private void addParticipant(Room room, RemoteParticipant remoteParticipant) {

        WritableMap event = new WritableNativeMap();
        event.putString("roomName", room.getName());
        event.putString("roomSid", room.getSid());
        event.putMap("participant", buildParticipant(remoteParticipant));

        pushEvent(this, ON_PARTICIPANT_CONNECTED, event);

        /*
         * Start listening for participant media events
         */
        remoteParticipant.setListener(mediaListener());

        for (final RemoteDataTrackPublication remoteDataTrackPublication :
              remoteParticipant.getRemoteDataTracks()) {
          /*
            * Data track messages are received on the thread that calls setListener. Post the
            * invocation of setting the listener onto our dedicated data track message thread.
            */
          if (remoteDataTrackPublication.isTrackSubscribed()) {
              dataTrackMessageThreadHandler.post(() -> addRemoteDataTrack(remoteParticipant,
                      remoteDataTrackPublication.getRemoteDataTrack()));
          }
      }
    }
 
Example 3
private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();

    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        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 4
Source Project: imsdk-android   Source File: QtalkPlugin.java    License: MIT License 6 votes vote down vote up
/**
     * 获取用户信息回传
     *
     * @param callback
     */
    @ReactMethod
    public void getUserInfo(Callback callback) {

        WritableNativeMap map = new WritableNativeMap();
        map.putString("userId", CurrentPreference.getInstance().getUserid());
        map.putString("clientIp", "192.168.0.1");
        map.putString("domain", QtalkNavicationService.getInstance().getXmppdomain());
//            map.putString("token", CurrentPreference.getInstance().getToken());
//            map.putString("q_auth", CurrentPreference.getInstance().getVerifyKey() == null ? "404" : CurrentPreference.getInstance().getVerifyKey());
        map.putString("ckey", getCKey());
        map.putString("httpHost", QtalkNavicationService.getInstance().getJavaUrl());
        map.putString("fileUrl", QtalkNavicationService.getInstance().getInnerFiltHttpHost());
        map.putString("qcAdminHost", QtalkNavicationService.getInstance().getQcadminHost());
//        if (!("ejabhost1".equals(QtalkNavicationService.getInstance().getXmppdomain()))) {
//            map.putInt("showOrganizational", 1);
//        } else {
//            map.putInt("showOrganizational", 0);
//        }
        map.putBoolean("showServiceState", CurrentPreference.getInstance().isMerchants());
        map.putBoolean("isQtalk", CommonConfig.isQtalk);

//            map.putDouble("timestamp", System.currentTimeMillis());
        callback.invoke(map);
    }
 
Example 5
@ReactMethod
public void getAccountsByType (String accountType, Promise promise) {
		manager = AccountManager.get(_reactContext);
		Account[] account_list = manager.getAccountsByType(accountType);
		WritableNativeArray result = new WritableNativeArray();

		for(Account account: account_list)
		{
			Integer index = indexForAccount(account);

			WritableNativeMap account_object = new WritableNativeMap();
			account_object.putInt("_index", (int)index);
			account_object.putString("name", account.name);
			account_object.putString("type", account.type);
			result.pushMap(account_object);
		}

		promise.resolve(result);
}
 
Example 6
Source Project: imsdk-android   Source File: QtalkPlugin.java    License: MIT License 6 votes vote down vote up
/**
     * 进行网络请求
     */
    @ReactMethod
    public void getSearchInfo(String url, ReadableMap params, ReadableMap cookie, Callback callback1, final Callback callback2) {
        final WritableNativeMap map = new WritableNativeMap();

        HttpUtil.PostUrl(url, params.toHashMap(), cookie.toHashMap(), new ProtocolCallback.UnitCallback<String>() {
            @Override
            public void onCompleted(String s) {
                map.putBoolean("isOk", true);
                map.putString("responseJson", s);
                callback2.invoke(map);
            }

            @Override
            public void onFailure(String errMsg) {
                map.putBoolean("isOk", false);
                map.putString("message", errMsg);
                callback2.invoke(map);
            }
        });


//
    }
 
Example 7
Source Project: react-native-GPay   Source File: DatePickerDialogTestCase.java    License: MIT License 6 votes vote down vote up
public void testCallback() throws Throwable {
  final WritableMap options = new WritableNativeMap();
  options.putDouble("date", getDateInMillis(2020, 5, 6));

  final DialogFragment datePickerFragment = showDialog(options);

  runTestOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          ((DatePickerDialog) datePickerFragment.getDialog())
              .getButton(DialogInterface.BUTTON_POSITIVE).performClick();
        }
      });

  getInstrumentation().waitForIdleSync();
  waitForBridgeAndUIIdle();

  assertEquals(0, mRecordingModule.getErrors());
  assertEquals(1, mRecordingModule.getDates().size());
  assertEquals(2020, (int) mRecordingModule.getDates().get(0)[0]);
  assertEquals(5, (int) mRecordingModule.getDates().get(0)[1]);
  assertEquals(6, (int) mRecordingModule.getDates().get(0)[2]);
}
 
Example 8
Source Project: react-native-android-sms-listener   Source File: SmsReceiver.java    License: MIT License 6 votes vote down vote up
private void receiveMessage(SmsMessage message) {
    if (mContext == null) {
        return;
    }

    if (! mContext.hasActiveCatalystInstance()) {
        return;
    }

    Log.d(
        SmsListenerPackage.TAG,
        String.format("%s: %s", message.getOriginatingAddress(), message.getMessageBody())
    );

    WritableNativeMap receivedMessage = new WritableNativeMap();

    receivedMessage.putString("originatingAddress", message.getOriginatingAddress());
    receivedMessage.putString("body", message.getMessageBody());

    mContext
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit(EVENT, receivedMessage);
}
 
Example 9
Source Project: react-native-fused-location   Source File: FusedLocationModule.java    License: MIT License 6 votes vote down vote up
private WritableMap convertLocationToJSON(Location l) {
    WritableMap params = new WritableNativeMap();
    params.putDouble("latitude", l.getLatitude());
    params.putDouble("longitude", l.getLongitude());
    params.putDouble("accuracy", l.getAccuracy());
    params.putDouble("altitude", l.getAltitude());
    params.putDouble("bearing", l.getBearing());
    params.putString("provider", l.getProvider());
    params.putDouble("speed", l.getSpeed());
    params.putString("timestamp", Long.toString(l.getTime()));
    boolean isMock;
    if (android.os.Build.VERSION.SDK_INT >= 18) {
        isMock = l.isFromMockProvider();
    } else {
        isMock = !Settings.Secure.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
    }
    params.putBoolean("mocked", isMock);
    return params;
}
 
Example 10
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
     * 发送反馈意见
     *
     * @param params
     */
    @ReactMethod
    public void sendAdviceMessage(ReadableMap params, final Callback callback) {
        String adviceMsg = params.getString("adviceText");
        boolean isUploadDb = params.getBoolean("logSelected");
        Logger.i("RNModule:发送反馈意见+++:" + adviceMsg);
        try {
            IMDatabaseManager.getInstance().manualCheckPoint();//手动checkpoint数据库
        }catch (Exception e){
            Logger.e("manualCheckPoint exception:" + e.getLocalizedMessage());
        }
//        FeedBackServcie.runFeedBackServcieService(CommonConfig.globalContext, new String[]{adviceMsg});
        IMNotificaitonCenter.getInstance().postMainThreadNotificationName(QtalkEvent.FEED_BACK, new String[]{adviceMsg},true,isUploadDb);
        WritableNativeMap map = new WritableNativeMap();
        map.putBoolean("ok", true);
        callback.invoke(map);

        saveRNActLog("Suggestions", "建议反馈", "我的页");
    }
 
Example 11
Source Project: react-native-amap   Source File: AMapViewManager.java    License: MIT License 6 votes vote down vote up
public WritableMap makeClickEventData(LatLng point) {
    WritableMap event = new WritableNativeMap();

    WritableMap coordinate = new WritableNativeMap();
    coordinate.putDouble("latitude", point.latitude);
    coordinate.putDouble("longitude", point.longitude);
    event.putMap("coordinate", coordinate);

    Projection projection = map.getProjection();
    Point screenPoint = projection.toScreenLocation(point);

    WritableMap position = new WritableNativeMap();
    position.putDouble("x", screenPoint.x);
    position.putDouble("y", screenPoint.y);
    event.putMap("position", position);

    return event;
}
 
Example 12
Source Project: react-native-fcm   Source File: ReactNativeJson.java    License: 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 = iterator.next();
        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 13
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
     * 获取用户通知是否显示详情
     *
     * @param callback
     */
    @ReactMethod
    public void getNotifyPushDetailsState(Callback callback) {

//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("getNotifySoundState",proFile.isTurnOnMsgSound());
//        map.putBoolean("state", proFile.isShowContentPush());
//        callback.invoke(map);

        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.SHOW_CONTENT);
        map.putBoolean("state", state);
        callback.invoke(map);
    }
 
Example 14
Source Project: ReactNative-AndAndroid   Source File: TransMissonMoudle.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void getTime() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String time = getTimeMillis();

            WritableMap writableMap = new WritableNativeMap();
            writableMap.putString("key", time);
            sendTransMisson(mReactContext, "EventName", writableMap);

        }
    }).start();
}
 
Example 15
Source Project: react-native-couchbase-lite   Source File: ReactNativeJson.java    License: 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 = iterator.next();
        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 16
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void selectGroupMemberForKick(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    List<Nick> userList = ConnectionUtil.getInstance().selectGroupMemberForKick(groupId);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example 17
Source Project: things-notification   Source File: CallListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            Log.d(TAG, "Call received: "+incomingNumber);
            if (!incomingNumber.isEmpty()) {
                WritableNativeMap params = new WritableNativeMap();
                params.putString("app", "phone");
                params.putString("text", incomingNumber);
                NotificationModule.sendEvent("notificationReceived", params);
            }
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example 18
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void selectMemberFromGroup(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    String searchText = params.getString("searchText");
    List<Nick> userList = ConnectionUtil.getInstance().selectMemberFromGroup(groupId, searchText);
    WritableNativeArray array = new WritableNativeArray();

    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example 19
@ReactMethod
public void subscribeWithFilter(String channel, Boolean subscribeOnReconnect, String filter, Integer id){
    OrtcClient client = null;
    if (queue.containsKey(id)) {
        client = queue.get(id);
        client.subscribeWithFilter(channel, subscribeOnReconnect, filter, new OnMessageWithFilter() {
            @Override
            public void run(OrtcClient ortcClient, String s, boolean filtered, String s1) {
                WritableMap params = new WritableNativeMap();
                params.putString("channel", s);
                params.putString("message", s1);
                params.putBoolean("filtered", filtered);
                String thisId = "" + RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
                sendEvent(getReactApplicationContext(), thisId + "-onMessageWithFilter", params);
            }
        });
    }
}
 
Example 20
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
     * 获取群信息
     *
     * @param groupId
     * @param callback
     */
    @ReactMethod
    public void getGroupInfo(final String groupId, final Callback callback) {
//        Nick mucNick =  ConnectionUtil.getInstance().getMucNickById(groupId);
        ConnectionUtil.getInstance().getMucCard(groupId, new IMLogicManager.NickCallBack() {
            @Override
            public void onNickCallBack(Nick nick) {
                WritableNativeMap map = new WritableNativeMap();
//                WritableNativeArray array = new WritableNativeArray();
                map.putString("GroupId", nick.getGroupId());
                map.putString("Name", nick.getName());
                map.putString("HeaderSrc", nick.getHeaderSrc());
                map.putString("Topic", nick.getTopic());
                map.putString("Introduce", nick.getIntroduce());

                WritableNativeMap re = new WritableNativeMap();
                re.putBoolean("ok", true);
                re.putMap("GroupInfo", map);
                callback.invoke(re);


            }
        }, true, true);
    }
 
Example 21
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
     * 同步群置顶信息
     *
     * @param groupId
     * @param callback
     */
    @ReactMethod
    public void syncGroupStickyState(String groupId, Callback callback) {
//        RecentConversation rc = new RecentConversation();
//        rc.setId(groupId);
//        rc.setRealUser(groupId);
//        rc = ConnectionUtil.getInstance().SelectConversationByRC(rc);
        UserConfigData userConfigData = new UserConfigData();
        userConfigData.setSubkey(groupId + "<>" + groupId);
        userConfigData.setKey(CacheDataType.kStickJidDic);
        UserConfigData ucd = ConnectionUtil.getInstance().selectUserConfigValueForKey(userConfigData);
//        recentConvDataModel.selectRecentConvById(rc);
//        panelView.setTop(rc.getTop()>0);
        WritableNativeMap map = new WritableNativeMap();
        map.putBoolean("state", ucd != null);
        callback.invoke(map);
    }
 
Example 22
Source Project: rn-camera-roll   Source File: CameraRollModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void getCameraImages(ReadableMap data, Callback onSuccess) {
    WritableNativeArray result = new WritableNativeArray();

    for(CameraImage imageData : CameraImagesManager.getCameraImages(this.context,
            data.getInt("first"), data.hasKey("after") ? data.getString("after") : "")) {
        WritableMap imageDataMap = new WritableNativeMap();
        imageDataMap.putString("uri", imageData.getLocalPath());
        imageDataMap.putInt("width", imageData.getWidth());
        imageDataMap.putInt("height", imageData.getHeight());
        imageDataMap.putInt("orientation", imageData.getOrientation());
        imageDataMap.putString("timestamp", Long.toString(imageData.getTimestamp()));

        result.pushMap(imageDataMap);
    }

    onSuccess.invoke(result);
}
 
Example 23
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
 * 查询不在星标联系人的好友
 *
 * @param callback
 */
@ReactMethod
public void selectFriendsNotInStarContacts(Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectFriendsNotInStarContacts();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("contacts", array);
    callback.invoke(re);
}
 
Example 24
Source Project: react-native-otp-verify   Source File: OtpBroadcastReceiver.java    License: MIT License 6 votes vote down vote up
private void receiveMessage(String message) {
    if (mContext == null) {
        return;
    }

    if (!mContext.hasActiveCatalystInstance()) {
        return;
    }

    WritableNativeMap receivedMessage = new WritableNativeMap();

    receivedMessage.putString("message", message);

    mContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(EVENT, message);
}
 
Example 25
@ReactMethod
public void subscribeWithOptions(ReadableMap options, Integer id){
    Map newOptions = recursivelyDeconstructReadableMap(options);
    OrtcClient client = null;
    if (queue.containsKey(id)) {
        client = queue.get(id);
        client.subscribeWithOptions(newOptions, new OnMessageWithOptions() {
            @Override
            public void run(OrtcClient sender, Map msgOptions) {
                String thisId = "" + RealtimeMessagingAndroid.getKeyByValue(queue, sender);
                WritableMap params = new WritableNativeMap();
                params.putString("channel", (String)msgOptions.get("channel"));
                params.putString("message", (String)msgOptions.get("message"));
                if (msgOptions.containsKey("filtered"))
                    params.putBoolean("filtered", (Boolean) msgOptions.get("filtered"));
                if (msgOptions.containsKey("seqId"))
                    params.putString("seqId", (String) msgOptions.get("seqId"));

                sendEvent(getReactApplicationContext(), thisId + "-onMessageWithOptions", params);
            }
        });
    }
}
 
Example 26
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void searchFilesByXmppId(String xmppid, Callback callback) {
    WritableNativeArray writableNativeArray = new WritableNativeArray();
    JSONArray jsonArray = ConnectionUtil.getInstance().searchFilesMsgByXmppid(xmppid);
    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            WritableNativeMap writableNativeMap = new WritableNativeMap();
            writableNativeMap.putString("from", jsonObject.optString("from"));
            writableNativeMap.putString("content", jsonObject.optString("content"));
            writableNativeMap.putString("time", jsonObject.optString("time"));
            writableNativeMap.putString("name", jsonObject.optString("name"));
            writableNativeMap.putString("headerSrc", jsonObject.optString("headerSrc"));
            writableNativeArray.pushMap(writableNativeMap);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
    if (callback != null) {
        WritableNativeMap map = new WritableNativeMap();
        map.putArray("files", writableNativeArray);
        callback.invoke(map);
    }
}
 
Example 27
Source Project: things-notification   Source File: NotificationModule.java    License: Apache License 2.0 6 votes vote down vote up
@ReactMethod
public void getInstalledApps(Promise promise) {
    WritableNativeArray params = new WritableNativeArray();
    PackageManager pm = reactContext.getPackageManager();
    List<ApplicationInfo> apps = pm.getInstalledApplications(0);
    for(ApplicationInfo app : apps) {
        if ((pm.getLaunchIntentForPackage(app.packageName) != null) &&
                !thisApp.equals(app.packageName)) {
            WritableNativeMap param = new WritableNativeMap();
            String appName = app.loadLabel(pm).toString();
            String appPackage = app.packageName;
            String appIcon = saveIcon(appPackage, app.loadIcon(pm));
            //Log.d(TAG, "name: "+appName);
            //Log.d(TAG, "app: "+appPackage);
            //Log.d(TAG, "icon: "+appIcon);
            param.putString("name", appName);
            param.putString("app", appPackage);
            param.putString("icon", appIcon);
            //sendEvent("installedApps", param);
            params.pushMap(param);
        }
    }
    promise.resolve(params);
}
 
Example 28
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());
            result.putNull(entry.getKey());
        }
    }

    return result;
}
 
Example 29
public void toggleVideo(boolean enabled) {
    if (localVideoTrack != null) {
        localVideoTrack.enable(enabled);

        WritableMap event = new WritableNativeMap();
        event.putBoolean("videoEnabled", enabled);
        pushEvent(CustomTwilioVideoView.this, ON_VIDEO_CHANGED, event);
    }
}
 
Example 30
@ReactMethod
public void getSafeAreaInsets(Callback cb) {
  Map<String, Object> constants = this._getSafeAreaInsets();
  WritableMap map = new WritableNativeMap();

  map.putInt("safeAreaInsetsTop", ((Float) constants.get("safeAreaInsetsTop")).intValue());
  map.putInt("safeAreaInsetsBottom", ((Float) constants.get("safeAreaInsetsBottom")).intValue());
  map.putInt("safeAreaInsetsLeft", ((Float) constants.get("safeAreaInsetsLeft")).intValue());
  map.putInt("safeAreaInsetsRight", ((Float) constants.get("safeAreaInsetsRight")).intValue());

  cb.invoke(map);
}