addScheme method

String addScheme(
  1. String xmlContent,
  2. String scheme
)

Injects a custom URL scheme intent-filter into AndroidManifest.xml. Returns the updated XML content. Idempotent.

Implementation

String addScheme(String xmlContent, String scheme) {
  final doc = XmlReader.parse(xmlContent);
  final activity = _findMainActivity(doc);

  // Check if scheme already exists in an intent-filter
  if (_hasScheme(activity, scheme)) {
    return xmlContent;
  }

  final newIntentFilter = _createSchemeIntentFilter(scheme);
  activity.children.add(newIntentFilter);

  return XmlReader.serialize(doc);
}