com.facebook.react.bridge.Arguments#fromBundle ( )源码实例Demo

下面列出了com.facebook.react.bridge.Arguments#fromBundle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    boolean allowForeground = Boolean.parseBoolean(getString(R.string.rnsb_allow_foreground));

    if(allowForeground || !isAppOnForeground(this)) {
        Bundle extras = intent.getExtras();
        WritableMap data = extras != null ? Arguments.fromBundle(extras) : Arguments.createMap();
        return new HeadlessJsTaskConfig(
                TASK_ID,
                data,
                Long.valueOf(getString(R.string.rnsb_default_timeout)),
                allowForeground);
    }

    stopSelf();
    return null;
}
 
源代码2 项目: react-native-fcm   文件: FIRMessagingModule.java
private WritableMap parseIntent(Intent intent){
    WritableMap params;
    Bundle extras = intent.getExtras();
    if (extras != null) {
        try {
            params = Arguments.fromBundle(extras);
        } catch (Exception e){
            Log.e(TAG, e.getMessage());
            params = Arguments.createMap();
        }
    } else {
        params = Arguments.createMap();
    }
    WritableMap fcm = Arguments.createMap();
    fcm.putString("action", intent.getAction());
    params.putMap("fcm", fcm);

    params.putInt("opened_from_tray", 1);
    return params;
}
 
源代码3 项目: rn-heartbeat   文件: HeartbeatEventService.java
@Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    return new HeadlessJsTaskConfig(
            "Heartbeat",
            extras != null ? Arguments.fromBundle(extras) : Arguments.createMap(),
            5000,
            true);
}
 
@Override
protected @Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
  Bundle extras = intent.getExtras();

  return new HeadlessJsTaskConfig(
    "RNCallKeepBackgroundMessage",
    Arguments.fromBundle(extras),
    60000,
    false
  );
}
 
@Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    return new HeadlessJsTaskConfig(
            "OnBoundaryEvent",
            extras != null ? Arguments.fromBundle(extras) : null,
            5000,
            true);
}
 
@Nullable @Override protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
  Log.d(LOG_TAG, "getTaskConfig() called with: intent = [" + intent + "]");
  Bundle extras = intent.getExtras();
  boolean allowExecutionInForeground = extras.getBoolean("allowExecutionInForeground", false);
  long timeout = extras.getLong("timeout", 2000);
  // For task with quick execution period additional check is required
  ReactNativeHost reactNativeHost =
      ((ReactApplication) getApplicationContext()).getReactNativeHost();
  boolean appInForeground = Utils.isReactNativeAppInForeground(reactNativeHost);
  if (appInForeground && !allowExecutionInForeground) {
    return null;
  }
  return new HeadlessJsTaskConfig(intent.getStringExtra("jobKey"), Arguments.fromBundle(extras),
      timeout, allowExecutionInForeground);
}
 
/**
 * Parses launch args passed to activity intent to WritableMap
 * @param activity to fetch the extra launch args
 * @return parsed writable map if it exist, otherwise empty map will be returned
 */
public static WritableMap parse(Activity activity) {
    if (activity != null) {
        Intent intent = activity.getIntent();
        if (intent != null) {
            Bundle launchArgs = intent.getBundleExtra(LAUNCH_ARGS);
            if (launchArgs != null) {
                return Arguments.fromBundle(launchArgs);
            }
        }
    }
    return Arguments.createMap();
}
 
@Override
protected @Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        return new HeadlessJsTaskConfig(
                TASK_KEY,
                Arguments.fromBundle(extras),
                60000, // timeout for the task
                true // optional: defines whether or not  the task is allowed in foreground. Default is false
        );
    }
    return null;
}
 
@Override
public void update(Observable observable, Object data) 
{            
  Intent intent = (Intent)data;

  if (intent.hasExtra("v2API"))
  {
      Bundle intentBundle = intent.getExtras();
      intentBundle.remove("com.symbol.datawedge.decode_data"); //  fb converter cannot cope with byte arrays
      intentBundle.remove("com.motorolasolutions.emdk.datawedge.decode_data"); //  fb converter cannot cope with byte arrays
      WritableMap map = Arguments.fromBundle(intentBundle);
      sendEvent(this.reactContext, "datawedge_broadcast_intent", map);
  }

  String action = intent.getAction();
  if (action.equals(ACTION_ENUMERATEDLISET)) 
  {
      Bundle b = intent.getExtras();
      String[] scanner_list = b.getStringArray(KEY_ENUMERATEDSCANNERLIST);
      WritableArray userFriendlyScanners = new WritableNativeArray();
      for (int i = 0; i < scanner_list.length; i++)
      {
          userFriendlyScanners.pushString(scanner_list[i]);
      }
      try
      {
        WritableMap enumeratedScannersObj = new WritableNativeMap();
        enumeratedScannersObj.putArray("Scanners", userFriendlyScanners);
        sendEvent(this.reactContext, "enumerated_scanners", enumeratedScannersObj);
      }
      catch (Exception e)
      {
          Toast.makeText(this.reactContext, "Error returning scanners", Toast.LENGTH_LONG).show();
          e.printStackTrace();
      }
  }
  else
  {
      //  Intent from the scanner (barcode has been scanned)
      String decodedSource = intent.getStringExtra(RECEIVED_SCAN_SOURCE);
      String decodedData = intent.getStringExtra(RECEIVED_SCAN_DATA);
      String decodedLabelType = intent.getStringExtra(RECEIVED_SCAN_TYPE);

      WritableMap scanData = new WritableNativeMap();
      scanData.putString("source", decodedSource);
      scanData.putString("data", decodedData);
      scanData.putString("labelType", decodedLabelType);
      sendEvent(this.reactContext, "barcode_scan", scanData);
  }
}