패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.2.8

receive_intent

Android Intents를 Flutter 환경으로 전달하기 위한 Flutter 플러그인.

Android
30일 다운로드
1.5만
좋아요
67
Pub 점수
150

패키지 설치

flutter pub add receive_intent

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

receive_intent 패키지는 Flutter 애플리케이션이 Android Intents를 수신하고 처리할 수 있도록 해주는 Flutter 플러그인입니다. 이를 통해 네이티브 Android 컴포넌트와 Flutter 환경 간의 원활한 통신을 가능하게 합니다. URL, 파일 공유, 사용자 정의 작업과 같은 외부 Intents를 통해 앱을 시작하는 것을 지원하며, 딥 링킹 및 앱 간 상호작용에 적합합니다. 이 플러그인은 extras, action, data URI 등의 인텐트 데이터에 접근할 수 있는 간단한 API를 제공합니다. Android에서 다른 앱이나 시스템 이벤트로부터 외부 트리거에 반응해야 하는 앱에 특히 유용합니다.

사용 사례

  • 딥링크 처리
  • 공유 파일 수신
  • 사용자 정의 URL 스키마 처리
  • 외부 소스에서 앱 실행
  • Android 브로드캐스트 수신기와의 통합

주요 기능

  • 간단한 의도 데이터 액세스
  • 딥 링크 지원
  • 공유 콘텐츠 처리
  • Android Intent 필터와 호환됩니다
  • 가볍고 통합하기 쉬움

적합한 대상

  • 딥 링크가 필요한 앱
  • 파일 공유 통합
  • 사용자 정의 URL 스키마 처리
  • 안드로이드 네이티브 상호 운용 시나리오
  • 외부 트리거 응답

고려 사항

  • 안드로이드 전용 기능
  • Android 매니페스트 구성이 필요합니다
  • 안드로이드 플랫폼에 제한됨
  • iOS 지원 없음
  • AndroidManifest.xml에 적절한 인텐트 필터 설정이 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

receive_intent

All Contributors pub.dev analysis pub points popularity likes GitHub issues GitHub milestone GitHub stars GitHub forks

A Flutter plugin to pass Android Intents to the Flutter environment.

Intent in Android is the "payload" for the communication between and within apps. This plugin passes the Intent, that "started" the Activity to the flutter environment. It also passes any "new Intents" that are received (via Activity.onNewIntent) while the Activity is already "started".

If the Intent was "started" via startActivityForResult, then this plugin also sends additional information (package name, app signature and component class name) about the "calling" Android Component, and can send "result" back (via Activity.setResult) to it.

This plugin is in active development. Any contribution, idea, criticism or feedback is welcomed.

Quick links

package https://pub.dev/packages/receive_intent
Git Repo https://github.com/daadu/receive_intent
Issue Tracker https://github.com/daadu/receive_intent/issues

Use cases

  • OAuth based App Flip - This was the initial motivation for this plugin. The plugin can be used to pass the Intent sent by Google App to the flutter environment - where the consent UI is shown - once it is authorized (or not), the result is sent back to the Google App.
  • Deeplink/Applink - This plugin is a generic implementation of uni_links plugin. While this plugin passes "any" Intents, uni_links only passes app-link/deep-link Intents.
  • Receive Share Intents - This plugin is a generic implementation of receive_sharing_intent plugin. While this plugin passes "any" Intents, receive_sharing_intent only passes "android.intent.action.SEND" (or related) Intents.
  • In general, if you want other apps to "start" your app, then this plugin can pass the Intent that "triggered" it to the flutter environment of the app. These Intent will give the app understanding of why the app was started. Check Getting started section to implement this.

Getting started

Add <intent-filter> to AndroidMainfest.xml

You need to add <intent-filter> to android/app/src/main/AndroidManifest.xml file:

<manifest ...>
  <!-- ... other tags -->
  <application ...>
    <activity ...>
      <!-- ... other tags -->
      
      <!-- Describe Intent your app can receive with <intent-filter>  -->
      <intent-filter>
        <action android:name="RECEIVE_INTENT_EXAMPLE_ACTION" />
        <category android:name="android.intent.category.DEFAULT"/>
      </intent-filter>
    </activity>
  </application>
</manifest>

In this example we want to receive Intent with action matching RECEIVE_INTENT_EXAMPLE_ACTION literal. This <intent-filter> should be added to the Activity that extends FlutterActivity (for project generated from template it is MainActivity).

<intent-filter> describes, what Intent the Activity is capable to recevie. To read more about "Intent and Intent Filter", encourage you to check official docs from Android.

Recevie and handle Intent that launched the Activity in Flutter

Inside flutter code, you can call ReceiveIntent.getInitialIntent() to get the Intent that started the Activity:

import 'package:receive_intent/receive_intent.dart';
// ...

  Future<void> _initReceiveIntent() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      final receivedIntent = await ReceiveIntent.getInitialIntent();
      // Validate receivedIntent and warn the user, if it is not correct,
      // but keep in mind it could be `null` or "empty"(`receivedIntent.isNull`).
    } on PlatformException {
      // Handle exception
    }
  }
  
// ...
Listen for any new Intent while the Activity is already running

To listen to new Intent while the Activity is running, you can use the ReceiveIntent.receivedIntentStream stream:

import 'package:receive_intent/receive_intent.dart';
// ...
  StreamSubscription _sub;
  
  Future<void> _initReceiveIntentit() async {
    // ... check initialIntent

    // Attach a listener to the stream
    _sub = ReceiveIntent.receivedIntentStream.listen((Intent? intent) {
      // Validate receivedIntent and warn the user, if it is not correct,
    }, onError: (err) {
      // Handle exception
    });

    // NOTE: Don't forget to call _sub.cancel() in dispose()
  }
// ...
Send result to the calling Activity (Optional)

If the calling Activty has "started" this activity with startActivityWithResult then you can send back result to that activity when ready with ReceiveIntent.setResult:

import 'package:receive_intent/receive_intent.dart';
// ...

  Future<void> _setActivityResult() async {
    // ...
    await ReceiveIntent.setResult(kActivityResultOk, data: {"sum": 123})
  }
// ...

To read more about "Starting Activities and Getting Results" pattern, encourage you to check official docs from Android.

Additionaly, in the case of activity started with startActivityWithResult, the Intent object will also have package name (intent.fromPackageName), app signatures (intent.fromSignatures) and component class name (intent.componentClassName) of the calling activity. This could be used to validate the calling app, so that sensitive information is not given to unintendent apps.

Tools to test it

You can test this with either adb or Intent Test app form Playstore.

adb

To invoke (start) our FlutterAcitivity with RECEIVE_INTENT_EXAMPLE_ACTION intent action name as mentioned in example <intent-filter> above:

adb shell 'am start -W -a RECEIVE_INTENT_EXAMPLE_ACTION -c android.intent.category.DEFAULT'

If you don't have adb in your path, but have $ANDROID_HOME env variable then use "$ANDROID_HOME"/platform-tools/adb ....

Note: Alternatively you could simply enter an adb shell and run the am commands in it.

Check example app

To know more or to get the working code check the example app.

Todo

  • Document API references properly
  • Receive Intent for non-Activity based intent-filter (BroadcastReceiver, Service)
  • Automatic testing

Contribute

Check the Todo section above, before you begin with any contribution.

  1. You'll need a GitHub account.
  2. Fork the repository.
  3. Pick an issue to work on from issue tracker.
  4. Implement it.
  5. Add your name and email in authors section in pubspec.yaml file.
  6. Send merge request.
  7. Star this project.
  8. Become a hero!!

Features and bugs

Please file feature requests and bugs at the issue tracker.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Harsh Bhikadia
Harsh Bhikadia

🤔 💻
Mateusz Soszyński
Mateusz Soszyński

💻
Chris Tomlinson
Chris Tomlinson

💻 🚧
eric-nextsense
eric-nextsense

🐛 💻
Tanay Neotia
Tanay Neotia

🐛 💻
Geert-Johan Riemer
Geert-Johan Riemer

💻
Derrick Gibelyou
Derrick Gibelyou

💻
Nacuta Claudiu
Nacuta Claudiu

🐛
Mr.monkey
Mr.monkey

🐛
MoovBuilder983
MoovBuilder983

💻
rmri
rmri

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트