Flutter plugin that uses an EventChannel - android

I'm creating a flutter plugin that uses a 3rd party SDK
The SDK has an override method called onIdleTimeout(), when this method fires the SDK logs the users out, and pulls up a native login view.
I don't want this native login view to pop up, so when this onIdleTimeout() fires I want to send a message back to the Flutter dart code that is using my plugin to simply let it know that the onIdleTimeout() method has fired
I've looked at examples of using EventChannels but none of them show using event channels inside of an custom override method in native code
any help is much appreciated thank you, I'm starting with the Android/Kotlin side of the plugin so any kotlin examples would be great

Found out I can just use a BasicMessageChannel to send a message from native to dart

Related

Android Native to React Native bridge

I've been searching on how to make a bridge between React Native and Android Native code for a while, but I still don't quite get it. I've read the documentation here , but I don't quite understand it.
What I want to do is, I want to build an apps that utilize push notification, but since I need to push message to China, I can't use GCM (thanks to the great firewall), so I use another third party push SDK.
I've managed to integrate the push into my apps (resulting a console.log() message whenever I push something), the next step is I want to re-route it to certain page
Any help will be appreciated :)
Note: If you are using common push notification (i.e. GCM and APNS), use this instead. Since I need to use another third party push service, I need to find a way myself to bridge the SDK (which is native) to React Native.
So after several hours tinkering with this problem, I found a solution for my problem. This solution divided into 2 parts:
emitter, this will emits an event whenever the server send a push.
listener, this will listen to the event that you emits before.
emitter
This happens on the native side (Android in my case)
For this part I learnt it from how this library did using GCM. And found a tutorial here on the RN documentation.
Basically after you receive your push on SomeBroadCastReceiver onReceive() function, you can pass the bundle as params in this function
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
//this eventName is a key so you need to remember it, because you need to call it on the listener
.emit(eventName, params);
listener
The listener will be built on the RN side. this documentation helps me. I missed this documentation before, because it only appear in the RN iOS docs only.
import { NativeEventEmitter, NativeModules } from 'react-native';
//import your already created package name here
const { YourCustomPackageName} = NativeModules;
then in ComponentWillMount()
const yourCustomPackageEmitter = new NativeEventEmitter(YourCustomPackageName);
pushListenerEmitter.addListener(eventName, this.handlePush, this);
then you just need to create handlePush function and get the params there
handlePush = (event) => {
console.log('event triggered..');
console.log(event);
}
The best way to do push notification is Deep Linking. If you are using React Navigation its much simple to do. Deep Linking React Native
You can define unique URL like yorApp://employee/1 and navigate easily to that screen.

Worklight WL.Client.getUserName

I have a Worklight 6.2 app. I am modifying the android java code to subscribe to a notification sent via Bluemix. After the user logs in, I would like to register the device using the userid that gets created. Is there an API call that I can use within the android code that is the equivalent to WL.Client.getUserName, or should I be calling the java code from my javascript and passing the userName to the java code? Thanks for any suggestions.
JT
There is no Java equivalent to this. This is a Worklight API.
What you can do is use the new WL.App.sendActionToNative method in Worklight 6.2 for to send a value to your native code and from there do what you need with it.
WL.App.sendActionToNative(“doSomething”, { customData: 12345} );
Where customdData is the WL.Client.getUserName.
On the native side you then need to use WLActionReciever (see What's New).
You could also opt to implement a basic Cordova plug-in that will move data from the web to native view.
The tutorial in the Getting Started page is doing exactly that.

Attach to Like!andTweed function in cocos2d-x Android App

I created Android App that is made by cocos2d-x.
I'd like to implement cooperation function with social network service (facebook and twitter )
For example, Like! button which separate news feed.tweet function.
But This function turned out to be a can of worms which I couldn't finish.
I found EziSocial. but I can't find any hints.
would you give me a
description of how to use and method of attach to existing app
We have series of tutorials available on our website. http://ezibyte.com/tutorials/
Disclaimer: I am the creator of EziSocial Plugin

How to press button in the internet programmatically

How do I invoke button clicks within page content of a TWebBrowser ? I have found this code for VCL and an older version of Delphi:
WebBrowser.OleObject.Document.GetElementByID('ID HERE').Click;
I am using XE5, developing for Android and iOS so I can not use the above code.
Any help or suggestions would be much appreciated. Thanks !
For Android: It is straight forward that you may need to write a JS function in web page and than you can call the JS function using JSInterfaces.
For iOS: You may call the instance method provided in UIWebView class to call the Javascript method. For reference please see : https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006950-CH3-SW21

Facebook Connect / phonegap - "nativeInterface" parameter within FB.init call, what it does?

So I have been trying to run the Facebook Connect example for PhoneGap / Android with no luck.
https://github.com/davejohnson/phonegap-plugin-facebook-connect *
There are some similar threads with the same problem.. conclusion is that "Facebook SDK is a moving point"
I have succesfully compiled previously apps using phoneGap & Eclipse.
Now following the example* for Android. If I do exactly what they suggest. App shows the buttons but nothing happens when I click on them.
After analyzing the code I have noticed that
function initFB(){
try {
FB.init({ appId: "45253452345234523", nativeInterface: PG.FB });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}
there is a parameter nativeInterface : PG.FB which is nowhere described within Facebook API for this call..
http://developers.facebook.com/docs/reference/javascript/FB.init/
what is more interesting is that when i remove this parameter.. suddenly Login button goes to Facebook page with Error Code API 191.
So my question is what this parameter is supposed to do? and why it is not in Facebook API?
I have found no info about this parameter in internet. I guess if it would be a case of an out-dated FB API there would be some info available.
Any ideas?
Thanks,
Marcin
The "nativeInterface: PG.FB" option is to tell PhoneGap to use the native authentication interface instead of the mobile web interface. If you don't add in the "PG.FB" option, you'll get redirected to Facebook's mobile authentication instead. It took me a while to figure this out too, and it's not well documented, but that's what is going on.
Two other things about the PhoneGap Facebook Plugin that are not up to date with the latest Facebook JavaScript SDK:
When using FB.login() you should be using the "scope" parameter, but PhoneGap expects the deprecated "perms" parameter.
When the authentication response from FB.login() you should be getting "response.authResponse", but instead "response.session" is what is given back. This means you'll have to pull out the OAuth Access token with "response.session.auth_token" instead of "response.authResponse.accessToken".
Hopefully they'll get to updating the PhoneGap Facebook Plugin, but for now I use if/else statements to detect if PhoneGap is there. You can check if PhoneGap is initialized by using:
if(window.PhoneGap) {
//PhoneGap Library is Loaded
}

Categories

Resources