toMap method

Map toMap()

Convert this Intent into a String holding a URI representation of it. The returned URI string has been properly URI encoded, so it can be used with {@link Uri#parse Uri.parse(String)}. The URI contains the Intent's data as the base URI, with an additional fragment describing the action, categories, type, flags, package, component, and extras.

You can convert the returned string back to an Intent with {@link #getIntent}.

@param flags Additional operating flags.

@return Returns a URI encoding URI string describing the entire contents of the Intent.

Implementation

// String toUri(int flags) {
//   StringBuffer uri = new StringBuffer();
//   if ((flags & URI_ANDROID_APP_SCHEME) != 0) {
//     if (_package == null) {
//       throw Exception(
//           "Intent must include an explicit package name to build an android-app: ${this}");
//     }
//     uri.write("android-app://");
//     uri.write(_package);
//     String? scheme;
//     if (_data != null) {
//       scheme = _data?.scheme;
//       if (scheme != null) {
//         uri.write('/');
//         uri.write(scheme);
//         String? authority = _data?.getEncodedAuthority();
//         if (authority != null) {
//           uri.write('/');
//           uri.write(authority);
//           String? path = _data?.getEncodedPath();
//           if (path != null) {
//             uri.write(path);
//           }
//           String? queryParams = _data?.getEncodedQuery();
//           if (queryParams != null) {
//             uri.write('?');
//             uri.write(queryParams);
//           }
//           String? fragment = _data?.getEncodedFragment();
//           if (fragment != null) {
//             uri.write('#');
//             uri.write(fragment);
//           }
//         }
//       }
//     }
//     toUriFragment(
//         uri,
//         null,
//         scheme == null ? Intent.ACTION_MAIN : Intent.ACTION_VIEW,
//         mPackage,
//         flags);
//     return uri.toString();
//   }

//   String? scheme;
//   if (_data != null) {
//     String data = _data.toString();
//     if ((flags & URI_INTENT_SCHEME) != 0) {
//       final int N = data.length;
//       for (int i = 0; i < N; i++) {
//         var c = data[i];
//         if ((c >= 'a' && c <= 'z') ||
//             (c >= 'A' && c <= 'Z') ||
//             (c >= '0' && c <= '9') ||
//             c == '.' ||
//             c == '-' ||
//             c == '+') {
//           continue;
//         }
//         if (c == ':' && i > 0) {
//           // Valid scheme.
//           scheme = data.substring(0, i);
//           uri.append("intent:");
//           data = data.substring(i + 1);
//           break;
//         }
//         // No scheme.
//         break;
//       }
//     }
//     uri.append(data);
//   } else if ((flags & URI_INTENT_SCHEME) != 0) {
//     uri.append("intent:");
//   }
//   toUriFragment(uri, scheme, Intent.ACTION_VIEW, null, flags);
//   return uri.toString();
// }

Map toMap() {
  var map = Map();
  map['action'] = _action;
  map['categories'] = _categories;
  map['component'] = _component?.toMap();
  map['extras'] = _extras?.toMap();
  map['package'] = _package;
  map['identifier'] = _identifier;
  map['flags'] = _flags;
  map['type'] = _type;
  map['data'] = _data?.toString();
  return map;
}