# app_links 3.1.0

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'app_links:3.1.0'
```
Published: 2022-04-28T14:37:02.480899Z
Expected archive SHA-256: 7a28970b667c02d2ed950ea11a2ddb116f023c52e0ec85a4fb1256ce008db7f2

Available in cache; verification: upstream_checksum
## Direct dependencies
- app_links_platform_interface: ^1.0.1
- app_links_web: ^1.0.0
- app_links_windows: ^1.0.0
- flutter: map[sdk:flutter]

## Package README (untrusted upstream documentation)
# app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler.

This plugin allows you to:
- catch HTTPS URLs to open your app instead of the browser (App Link / Universal Link).
- catch custom schemes to open your app (Deep Link / Custom URL scheme).

## Getting Started

Before using the plugin, you'll need to setup each platforms you target.

### Android

- App Links: [Documentation](https://developer.android.com/training/app-links/verify-site-associations)
- Deep Links: [Documentation](https://developer.android.com/training/app-links/deep-linking)

### iOs

- Universal Links: [Documentation](https://developer.apple.com/documentation/safariservices/supporting_associated_domains)
- Custom URL schemes: [Documentation](https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app)

### Windows

<details>
  <summary>Setup</summary>

Declare this method in <PROJECT_DIR>\windows\runner\win32_window.h
```cpp
  // Dispatches link if any.
  // This method enables our app to be with a single instance too.
  // This is optional but mandatory if you want to catch further links in same app.
  bool SendAppLinkToInstance(const std::wstring& title);
```

Add this inclusion at the top of <PROJECT_DIR>\windows\runner\win32_window.cpp
```cpp
#include <app_links_windows/app_links_windows_plugin.h>
```

Add this method in <PROJECT_DIR>\windows\runner\win32_window.cpp
```cpp
bool Win32Window::SendAppLinkToInstance(const std::wstring& title) {
  // Find our exact window
  HWND hwnd = ::FindWindow(kWindowClassName, title.c_str());
  
  if (hwnd) {
    // Dispatch new link to current window
    SendAppLink(hwnd);

    // (Optional) Restore our window to front in same state
    WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
    GetWindowPlacement(hwnd, &place);
    switch(place.showCmd) {
      case SW_SHOWMAXIMIZED:
          ShowWindow(hwnd, SW_SHOWMAXIMIZED);
          break;
      case SW_SHOWMINIMIZED:
          ShowWindow(hwnd, SW_RESTORE);
          break;
      default:
          ShowWindow(hwnd, SW_NORMAL);
          break;
    }
    SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
    SetForegroundWindow(hwnd);
    // END Restore

    // Window has been found, don't create another one.
    return true;
  }

  return false;
}
```

Add the call to the previous method in `CreateAndShow`
```cpp
bool Win32Window::CreateAndShow(const std::wstring& title,
                                const Point& origin,
                                const Size& size) {
if (SendAppLinkToInstance(title)) {
    return false;
}

...
```

Great!

Now you can register your own scheme.  
This package can not do it for you.  
You can make it with [url_protocol](https://pub.dev/packages/url_protocol) inside you app.  
But... The most relevant is to include those registry modifications into your installer to allow the unregistration.
</details>

---
  
### AppLinks usage
```dart
final _appLinks = AppLinks();

// Get the initial/first link.
// This is also useful when app was terminated (i.e. not started)
final uri = await _appLinks.getInitialAppLink();
// Do something (navigation, ...)

// Subscribe to further events when app is started.
// (Use stringLinkStream to get it as [String])
_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
    // Do something (navigation, ...)
});

...

// Maybe later. Get the latest link.
final uri = await _appLinks.getLatestAppLink();
```

Android notes:
- Intent action is filtered by `Intent.ACTION_VIEW`.

- By default, flutter Activity is set with `android:launchMode="singleTop"`.
This is perfectly fine and expected, but this launches another instance of your app, specifically for the requested view.  
If you don't want this behaviour, you can set `android:launchMode="singleInstance"` in your `AndroidManifest.xml` and avoid another flutter warmup.

## Tests
The following commands will help you to test links.

### Android
```sh
adb shell am start
    -W -a android.intent.action.VIEW
    -d "<URI>" <PACKAGE>
```
For App Links, you can also test it from Android Studio: [Documentation](https://developer.android.com/studio/write/app-link-indexing#testindent).

### iOs
```sh
/usr/bin/xcrun simctl openurl booted "<URI>"
```

## Changelog
## 3.1.0
* feat: Add Windows support.

## 3.0.2
* fix: iOS `application` callbacks do not return `true` anymore.

## 3.0.1
* core: Improve Android code.

## 3.0.0
* core: __Breaking__ API changed to use stream instead of callback.
* fix: Consistent behaviour between iOS & Android with (deffered) stream usage (for onAppLink vs. getInitialLink "duplicated" links).
* fix: remove example splashscreen deprecation.

## 2.2.2
* core: Add linter.
* fix: Get rid of Android LocalBroadcastReceiver deprecation (removed dependency & import...).

## 2.2.1
* fix: Duplicated iOS call when app is on terminated status.
* fix: iOS `application` callback does not return `true` anymore.
* fix: Get rid of Android LocalBroadcastReceiver deprecation.
* core: Updated dependencies.

## 2.2.0
* Add web support. (getInitialAppLink() only).

## 2.1.0
* Breaking: String uri added on `onAppLink` for custom handling like uppercased uri.
* Feat: `getInitialAppLinkString` and `getLatestAppLinkString` added to reflect the above change.

## 2.0.0+1
* Minimal sample added (Thanks to @JamesCullum).

## 2.0.0
* Add null safety support.

## 1.0.0
* Same as 0.2.0.
* No known issue. Bumping to 1.0 to be prepared for null safety version.

## 0.2.0
* Add configurations in example.

## 0.1.0+2
* Update README.md.

## 0.1.0+1
* Add documentation.
* Format dart source code.

## 0.1.0
* Initial release.
* Android App Links, Deep Links, iOs Universal Links and Custom URL schemes.







 
