UniWebViewExternalActivityResult.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // UniWebViewExternalActivityResult.cs
  3. // Created by Wang Wei (@onevcat) on 2025-06-18.
  4. //
  5. // This file is a part of UniWebView Project (https://uniwebview.com)
  6. // By purchasing the asset, you are allowed to use this code in as many as projects
  7. // you want, only if you publish the final products under the name of the same account
  8. // used for the purchase.
  9. //
  10. // This asset and all corresponding files (such as source code) are provided on an
  11. // "as is" basis, without warranty of any kind, express of implied, including but not
  12. // limited to the warranties of merchantability, fitness for a particular purpose, and
  13. // noninfringement. In no event shall the authors or copyright holders be liable for any
  14. // claim, damages or other liability, whether in action of contract, tort or otherwise,
  15. // arising from, out of or in connection with the software or the use of other dealing in the software.
  16. //
  17. /// <summary>
  18. /// The status of an external activity result on Android.
  19. /// </summary>
  20. public enum UniWebViewExternalActivityResultStatus {
  21. /// <summary>
  22. /// The external activity completed successfully and returned a result.
  23. /// </summary>
  24. Ok = -1,
  25. /// <summary>
  26. /// The external activity was canceled by the user or did not return a result.
  27. /// </summary>
  28. Canceled = 0
  29. }
  30. /// <summary>
  31. /// Represents the result returned from an external Android activity that was launched from the web view.
  32. ///
  33. /// When a web page in the web view navigates to a custom URL scheme (such as `upi://` for payment apps),
  34. /// UniWebView launches the corresponding external app using Android's `startActivityForResult`. When that
  35. /// app finishes and returns a result, this object carries the result data back to your Unity code.
  36. ///
  37. /// This is only available on Android. On iOS and macOS, external app communication uses URL schemes and
  38. /// deep links instead.
  39. /// </summary>
  40. public class UniWebViewExternalActivityResult {
  41. /// <summary>
  42. /// The original URL that triggered the external app launch (e.g., `upi://pay?pa=...`).
  43. /// </summary>
  44. public string Url { get; private set; }
  45. /// <summary>
  46. /// The result status returned by the external activity.
  47. /// </summary>
  48. public UniWebViewExternalActivityResultStatus Status { get; private set; }
  49. /// <summary>
  50. /// The raw integer result code returned by the external activity. This is the Android `resultCode`
  51. /// value. In most cases, use the `Status` property instead for a more readable representation.
  52. /// </summary>
  53. public int ResultCode { get; private set; }
  54. /// <summary>
  55. /// The data returned by the external activity, serialized as a JSON string.
  56. ///
  57. /// The JSON object contains all extras from the result Intent. For UPI payment apps, this typically
  58. /// includes a `"response"` key with a query-string-formatted value containing fields like `txnId`,
  59. /// `Status`, and `responseCode`.
  60. ///
  61. /// If the result Intent also carries a data URI, it is included under the `"__dataUri"` key.
  62. ///
  63. /// This value is an empty string if the external activity returned no data.
  64. /// </summary>
  65. public string Data { get; private set; }
  66. internal UniWebViewExternalActivityResult(string url, int resultCode, string data) {
  67. Url = url;
  68. ResultCode = resultCode;
  69. Status = resultCode == -1
  70. ? UniWebViewExternalActivityResultStatus.Ok
  71. : UniWebViewExternalActivityResultStatus.Canceled;
  72. Data = data;
  73. }
  74. }