All Projects → bsorrentino → Cordova Broadcaster

bsorrentino / Cordova Broadcaster

Licence: mit
Cordova Plugin to allow message exchange between javascript and native (and viceversa)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Cordova Broadcaster

Cordova Plugin Remote Injection
DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Stars: ✭ 90 (-13.46%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Disable Bitcode
Cordova plugin to disable bitcode in iOS build settings
Stars: ✭ 19 (-81.73%)
Mutual labels:  cordova, cordova-plugin
Cordova Admob Pro
🔥 Cordova Plugin for Google AdMob, DFP, ADX. Easy monetization using mobile Ad, with single line of JavaScript. Compatible with Cordova CLI, Inoic, PhoneGap Build, etc.
Stars: ✭ 690 (+563.46%)
Mutual labels:  cordova, cordova-plugin
Google Analytics Plugin
Cordova Google Analytics Plugin for Android & iOS
Stars: ✭ 90 (-13.46%)
Mutual labels:  cordova, cordova-plugin
Unityionicintegration
A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
Stars: ✭ 94 (-9.62%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Admob Free
Cordova AdMob Plugin
Stars: ✭ 508 (+388.46%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Stripe
A Cordova plugin that lets you use Stripe's Native SDKs for Android and iOS.
Stars: ✭ 90 (-13.46%)
Mutual labels:  cordova, cordova-plugin
scanbot-sdk-example-ionic
Scanbot scanner SDK example app for Ionic with Cordova.
Stars: ✭ 24 (-76.92%)
Mutual labels:  cordova, cordova-plugin
Cl.kunder.webview
This cordova plugin enables you to open a second webview
Stars: ✭ 36 (-65.38%)
Mutual labels:  cordova, cordova-plugin
Awesome Cordova Plugins
A curated list of awesome Cordova Apache Plugins https://cordova.apache.org/plugins/
Stars: ✭ 33 (-68.27%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Qrscanner
A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
Stars: ✭ 485 (+366.35%)
Mutual labels:  cordova, cordova-plugin
Blinkid Cordova
ID scanning for cross-platform apps built with Cordova and Phonegap.
Stars: ✭ 44 (-57.69%)
Mutual labels:  cordova, cordova-plugin
Vue Cordova
Vue.js plugin for Cordova
Stars: ✭ 328 (+215.38%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Camera Preview
Cordova plugin that allows camera interaction from HTML code
Stars: ✭ 528 (+407.69%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Geofence
Geofencing plugin for cordova
Stars: ✭ 261 (+150.96%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Linkedin
Cordova plugin for LinkedIn
Stars: ✭ 17 (-83.65%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-today-widget
Add a today widget app extension target to your cordova project.
Stars: ✭ 51 (-50.96%)
Mutual labels:  cordova, cordova-plugin
ionic-native-sms-retriever-plugin-master
Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
Stars: ✭ 16 (-84.62%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Permissionscope
🔓 Cordova plugin to handle iOS permissions
Stars: ✭ 27 (-74.04%)
Mutual labels:  cordova, cordova-plugin
Ionic4
This repo contains example code for ionic4. Get Step by Step tutorial of this repo examples using https://ampersandacademy.com/tutorials/ionic-framework-4
Stars: ✭ 37 (-64.42%)
Mutual labels:  cordova, cordova-plugin

Cordova Broadcaster

Cordova Plugin to allow message exchange between javascript and native (and viceversa).

npm Join the chat at https://gitter.im/bsorrentino/cordova-broadcaster

Ingredient Technologies

Broadcaster plugin providing bridge for the following native technologies:

target OS Native Technology
IOS NotificationCenter
Android LocalBroadcastManager

News

date infos refs
Mar 19, 2020 Concerning Android I've added support for broadcast Intent to external Apps, receive broadcast Intents from external Apps, Flags & Category on Intent insipred by navarrojava's fork
Jan 16, 2018 I've developed a complete ionic3 sample project using broadcaster ionic-broadcaster-sample
Jan 28, 2017 such plugin has been added to ionic-native distribution How to is available here

Installation

$ cordova create <PATH> [ID [NAME [CONFIG]]] [options]
$ cd <PATH>
$ cordova platform add [ios|android]
$ cordova plugin add cordova-plugin-broadcaster

Usage:

From Native to Javascript

Javascript

    console.log( "register didShow received!" );

    var listener = function( e ) {
      //log: didShow received! userInfo: {"data":"test"}
      console.log( "didShow received! userInfo: " + JSON.stringify(e)  );
    }

    window.broadcaster.addEventListener( "didShow", listener);

From ANDROID to Javascript - Extra ANDROID features

Listen for global message

if( cordova.platformId === "android" ) {

    var listener = function( e ) {
      //log: didShow received! userInfo: {"data":"test"}
      console.log( "CONNECTIVITY_CHANGE: " + JSON.stringify(e)  );
    }
    var isGlobal = true
    window.broadcaster.addEventListener( 'android.net.conn.CONNECTIVITY_CHANGE', isGlobal, listener);
}

ANDROID

final Intent intent = new Intent("didShow");

final Bundle child = new Bundle();
child.putString( "name", "joker");

final Bundle b = new Bundle();
b.putString( "data", "test");
b.putBoolean( "valid", true );
b.putBundle( "child", child );

intent.putExtras( b);

LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent);

IOS

Objective-C
    NSDictionary * payload = @{
        @"data":@"test",
        @"valid": [NSNumber numberWithBool:YES],
        @"child": @{ @"name": @"joker" }
    };
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"TEST.EVENT"
                                                        object:nil
                                                      userInfo:payload];
Swift 5.x
  let payload:[String:Any] = [
          "data":"test",
          "valid": true,
          "child":[ "name": "joker" ]
      ]

  let nc = NotificationCenter.default
  nc.post(name:Notification.Name("didShow"), object: nil, userInfo: payload)

BROWSER

let event = new CustomEvent("didShow", { detail: { data:"test"} } );
document.dispatchEvent( event )

From Javascript to Native - ANDROID,BROWSER,IOS

Javascript

  window.broadcaster.fireNativeEvent( "test.event", { item:'test data' }, function() {
    console.log( "event fired!" );
    } );

From Javascript to ANDROID - Extra ANDROID features

Send a message with "flags" and "category"

if( cordova.platformId === "android" ) {

  // send a message with "flags" and "category"
  window.broadcaster.fireNativeEvent( "message", { extras:{ item:'test data' }, flags:0, category:'android.intent.category.INFO'}, function() {
    console.log( "event fired!" );
  });
}

Send a global message

if( cordova.platformId === "android" ) {

  // send a global message
  var isGlobal = true
  window.broadcaster.fireNativeEvent( "GLOBAL_ACTION", isGlobal, { item:'test data' }, function() {
    console.log( "event fired!" );
  });

}

Send a global message with "flags" and "category"

if( cordova.platformId === "android" ) {

  // send a global message with "flags" and "category"
  var isGlobal = true
  window.broadcaster.fireNativeEvent( "GLOBAL_ACTION", isGlobal, { extras:{ item:'test data' }, flags:0, category:'android.intent.category.INFO'}, function() {
    console.log( "event fired!" );
  });

}

ANDROID

final BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String data = intent.getExtras().getString("data");

        Log.d("CDVBroadcaster",
                String.format("Native event [%s] received with data [%s]", intent.getAction(), data));

    }
};

LocalBroadcastManager.getInstance(this)
            .registerReceiver(receiver, new IntentFilter("test.event"));
}

IOS

Objective-C
[[NSNotificationCenter defaultCenter] addObserverForName:@"test.event"
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification *notification) {
                                                      NSLog(@"Handled 'test.event' [%@]", notification.userInfo[@"item"]);
                                                    }];
Swift 5.x
let nc = NotificationCenter.default
nc.addObserver(forName:Notification.Name(rawValue:"test.event"),
               object:nil, queue:nil) {
  notification in
  print( "\(notification.userInfo)")
}

BROWSER

document.addEventListener( "test.event", ( ev:Event ) => {
  console.log( "test event", ev.detail );
});

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].