Java Code Examples for io.flutter.plugin.common.EventChannel#setStreamHandler()

The following examples show how to use io.flutter.plugin.common.EventChannel#setStreamHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlutterYoutubePlugin.java    From FlutterYoutube with Apache License 2.0 6 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final MethodChannel channel = new MethodChannel(registrar.messenger(), "PonnamKarthik/flutter_youtube");
  channel.setMethodCallHandler(new FlutterYoutubePlugin(registrar.activity()));
  registrar.addActivityResultListener(new PluginRegistry.ActivityResultListener() {
    @Override
    public boolean onActivityResult(int i, int i1, Intent intent) {
      if(i == YOUTUBE_PLAYER_RESULT) {
        if(intent != null) {
          if(intent.getIntExtra("done", -1) == 0) {
            if(events != null) {
              events.success("done");
            }
          }
        }
      }
      return false;
    }
  });

  final EventChannel eventChannel = new EventChannel(registrar.messenger(), STREAM_CHANNEL_NAME);
  FlutterYoutubePlugin youtubeWithEventChannel = new FlutterYoutubePlugin(registrar.activity());
  eventChannel.setStreamHandler(youtubeWithEventChannel);
}
 
Example 2
Source File: FlutterBarcodeScannerPlugin.java    From flutter_barcode_scanner with MIT License 5 votes vote down vote up
/**
 * Setup method
 * Created after Embedding V2 API release
 *
 * @param messenger
 * @param applicationContext
 * @param activity
 * @param registrar
 * @param activityBinding
 */
private void createPluginSetup(
        final BinaryMessenger messenger,
        final Application applicationContext,
        final Activity activity,
        final PluginRegistry.Registrar registrar,
        final ActivityPluginBinding activityBinding) {


    this.activity = (FlutterActivity) activity;
    eventChannel =
            new EventChannel(messenger, "flutter_barcode_scanner_receiver");
    eventChannel.setStreamHandler(this);


    this.applicationContext = applicationContext;
    channel = new MethodChannel(messenger, CHANNEL);
    channel.setMethodCallHandler(this);
    if (registrar != null) {
        // V1 embedding setup for activity listeners.
        observer = new LifeCycleObserver(activity);
        applicationContext.registerActivityLifecycleCallbacks(
                observer); // Use getApplicationContext() to avoid casting failures.
        registrar.addActivityResultListener(this);
    } else {
        // V2 embedding setup for activity listeners.
        activityBinding.addActivityResultListener(this);
        lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
        observer = new LifeCycleObserver(activity);
        lifecycle.addObserver(observer);
    }
}
 
Example 3
Source File: AmapLocationPlugin.java    From location_plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
	final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "plugin.kinsomy.com/methodchannel");
	final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugin.kinsomy.com/eventchannel");
	final AmapLocationPlugin instance = new AmapLocationPlugin(registrar);
	methodChannel.setMethodCallHandler(instance);
	eventChannel.setStreamHandler(instance);
}
 
Example 4
Source File: AeyriumSensorPlugin.java    From aeyrium-sensor with MIT License 5 votes vote down vote up
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
  final EventChannel sensorChannel =
          new EventChannel(registrar.messenger(), SENSOR_CHANNEL_NAME);
  sensorChannel.setStreamHandler(
          new AeyriumSensorPlugin(registrar.context(), Sensor.TYPE_ROTATION_VECTOR, registrar));

}
 
Example 5
Source File: NativeDeviceOrientationPlugin.java    From flutter_native_device_orientation with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), METHOD_CHANEL);
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), EVENT_CHANNEL);
    final NativeDeviceOrientationPlugin instance = new NativeDeviceOrientationPlugin(registrar.activeContext());

    methodChannel.setMethodCallHandler(instance);
    eventChannel.setStreamHandler(instance);
}
 
Example 6
Source File: OtaUpdatePlugin.java    From ota_update with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    OtaUpdatePlugin plugin = new OtaUpdatePlugin(registrar);
    final EventChannel progressChannel = new EventChannel(registrar.messenger(), "sk.fourq.ota_update");
    progressChannel.setStreamHandler(plugin);
    registrar.addRequestPermissionsResultListener(plugin);
}
 
Example 7
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    if (registrar.activity() == null) {
        // When a background flutter view tries to register the plugin, the registrar has no activity.
        // We stop the registration process as this plugin is foreground only.
        return;
    }
    final MethodChannel channel = new MethodChannel(registrar.messenger(), "wifi_iot");
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugins.wififlutter.io/wifi_scan");
    final WifiIotPlugin wifiIotPlugin = new WifiIotPlugin(registrar.activity());
    eventChannel.setStreamHandler(wifiIotPlugin);
    channel.setMethodCallHandler(wifiIotPlugin);

    registrar.addViewDestroyListener(new ViewDestroyListener() {
        @Override
        public boolean onViewDestroy(FlutterNativeView view) {
            if (!wifiIotPlugin.ssidsToBeRemovedOnExit.isEmpty()) {
                List<WifiConfiguration> wifiConfigList =
                        wifiIotPlugin.moWiFi.getConfiguredNetworks();
                for (String ssid : wifiIotPlugin.ssidsToBeRemovedOnExit) {
                    for (WifiConfiguration wifiConfig : wifiConfigList) {
                        if (wifiConfig.SSID.equals(ssid)) {
                            wifiIotPlugin.moWiFi.removeNetwork(wifiConfig.networkId);
                        }
                    }
                }
            }
            return false;
        }
    });
}
 
Example 8
Source File: NotificationsPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
    final EventChannel channel = new EventChannel(registrar.messenger(), EVENT_CHANNEL_NAME);
    Context context = registrar.activeContext();
    NotificationsPlugin plugin = new NotificationsPlugin(context);
    channel.setStreamHandler(plugin);
}
 
Example 9
Source File: LightPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final EventChannel eventChannel =
          new EventChannel(registrar.messenger(), STEP_COUNT_CHANNEL_NAME);
  eventChannel.setStreamHandler(
          new LightPlugin(registrar.context(), Sensor.TYPE_LIGHT));
}
 
Example 10
Source File: PedometerPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  final EventChannel eventChannel =
          new EventChannel(registrar.messenger(), STEP_COUNT_CHANNEL_NAME);
  eventChannel.setStreamHandler(
          new PedometerPlugin(registrar.context(), Sensor.TYPE_STEP_COUNTER));
}
 
Example 11
Source File: MovisensFlutterPlugin.java    From flutter-plugins with MIT License 5 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    // Set up plugin instance
    MovisensFlutterPlugin plugin = new MovisensFlutterPlugin(registrar);

    // Set up method channel
    final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "movisens.method_channel");
    methodChannel.setMethodCallHandler(plugin);

    // Set up event channel
    final EventChannel eventChannel = new EventChannel(registrar.messenger(), "movisens.event_channel");
    eventChannel.setStreamHandler(plugin);
}
 
Example 12
Source File: SmsPlugin.java    From flutter_sms with MIT License 4 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {

    registrar.addRequestPermissionsResultListener(Permissions.getRequestsResultsListener());

    // SMS receiver
    final SmsReceiver receiver = new SmsReceiver(registrar);
    final EventChannel receiveSmsChannel = new EventChannel(registrar.messenger(),
            CHANNEL_RECV, JSONMethodCodec.INSTANCE);
    receiveSmsChannel.setStreamHandler(receiver);

    // SMS status receiver
    new EventChannel(registrar.messenger(), CHANNEL_SMS_STATUS, JSONMethodCodec.INSTANCE)
            .setStreamHandler(new SmsStateHandler(registrar));

    /// SMS sender
    final SmsSender sender = new SmsSender(registrar);
    final MethodChannel sendSmsChannel = new MethodChannel(registrar.messenger(),
            CHANNEL_SEND, JSONMethodCodec.INSTANCE);
    sendSmsChannel.setMethodCallHandler(sender);

    /// SMS query
    final SmsQuery query = new SmsQuery(registrar);
    final MethodChannel querySmsChannel = new MethodChannel(registrar.messenger(), CHANNEL_QUER, JSONMethodCodec.INSTANCE);
    querySmsChannel.setMethodCallHandler(query);

    /// Contact query
    final ContactQuery contactQuery = new ContactQuery(registrar);
    final MethodChannel queryContactChannel = new MethodChannel(registrar.messenger(), CHANNEL_QUER_CONT, JSONMethodCodec.INSTANCE);
    queryContactChannel.setMethodCallHandler(contactQuery);

    /// Contact Photo query
    final ContactPhotoQuery contactPhotoQuery = new ContactPhotoQuery(registrar);
    final MethodChannel queryContactPhotoChannel = new MethodChannel(registrar.messenger(), CHANNEL_QUER_CONT_PHOTO, StandardMethodCodec.INSTANCE);
    queryContactPhotoChannel.setMethodCallHandler(contactPhotoQuery);

    /// User Profile
    final UserProfileProvider userProfileProvider = new UserProfileProvider(registrar);
    final MethodChannel userProfileProviderChannel = new MethodChannel(registrar.messenger(), CHANNEL_USER_PROFILE, JSONMethodCodec.INSTANCE);
    userProfileProviderChannel.setMethodCallHandler(userProfileProvider);

    //Sim Cards Provider
    new MethodChannel(registrar.messenger(), CHANNEL_SIM_CARDS, JSONMethodCodec.INSTANCE)
            .setMethodCallHandler(new SimCardsProvider(registrar));
}
 
Example 13
Source File: ScreenStatePlugin.java    From flutter-plugins with MIT License 4 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
  ScreenStatePlugin plugin = new ScreenStatePlugin(registrar);
  final EventChannel eventChannel = new EventChannel(registrar.messenger(), "screenStateEvents");
  eventChannel.setStreamHandler(plugin);
}
 
Example 14
Source File: NoiseMeterPlugin.java    From flutter-plugins with MIT License 4 votes vote down vote up
/**
 * Plugin registration.
 */
public static void registerWith(Registrar registrar) {
    EventChannel eventChannel = new EventChannel(registrar.messenger(), EVENT_CHANNEL_NAME);
    eventChannel.setStreamHandler(new NoiseMeterPlugin());
    NoiseMeterPlugin.registrar = registrar;
}
 
Example 15
Source File: FlutterRefreshEventPlugin.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public static void registerWith(FlutterPluginRegistry pluginRegistry, String pageName, EventChannel.StreamHandler handler) {
    final String channelName = CHANNEL_NAME + "/" + pageName;
    final EventChannel channel = new EventChannel(pluginRegistry.registrarFor(channelName).messenger(), channelName);
    channel.setStreamHandler(handler);
}
 
Example 16
Source File: MedcorderAudioPlugin.java    From flutter_audio with MIT License 3 votes vote down vote up
public static void registerWith(Registrar registrar) {
  final MedcorderAudioPlugin plugin = new MedcorderAudioPlugin(registrar.activity());

  final MethodChannel methodChannel = new MethodChannel(registrar.messenger(), "medcorder_audio");
  methodChannel.setMethodCallHandler(plugin);

  final EventChannel eventChannel = new EventChannel(registrar.messenger(), "medcorder_audio_events");
  eventChannel.setStreamHandler(plugin);

}