use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.
the class InterstitialAdManager method showAd.
@ReactMethod
public void showAd(String placementId, Promise p) {
if (mPromise != null) {
p.reject("E_FAILED_TO_SHOW", "Only one `showAd` can be called at once");
return;
}
ReactApplicationContext reactContext = this.getReactApplicationContext();
mPromise = p;
mInterstitial = new InterstitialAd(reactContext, placementId);
mInterstitial.setAdListener(this);
mInterstitial.loadAd();
}
use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.
the class InterstitialAdManager method loadAd.
@ReactMethod
public void loadAd(String placementId, Promise p) {
ReactApplicationContext reactContext = this.getReactApplicationContext();
mViewAtOnce = true;
mPromise = p;
mInterstitial = new InterstitialAd(reactContext, placementId);
mInterstitial.loadAd();
}
use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.
the class NativeAdManager method init.
/**
* Initialises native ad manager for a given placement id and ads to request.
* This method is run on the UI thread
*
* @param placementId
* @param adsToRequest
*/
@ReactMethod
public void init(final String placementId, final int adsToRequest) {
final ReactApplicationContext reactContext = this.getReactApplicationContext();
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
final NativeAdsManager adsManager = new NativeAdsManager(reactContext, placementId, adsToRequest);
adsManager.setListener(NativeAdManager.this);
mAdsManagers.put(placementId, adsManager);
adsManager.loadAds();
}
});
}
use of com.facebook.react.bridge.ReactApplicationContext in project react-native-twilio-programmable-voice by hoxfon.
the class VoiceFirebaseMessagingService method onMessageReceived.
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Bundle data: " + remoteMessage.getData());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
// If notification ID is not provided by the user for push notification, generate one at random
Random randomNumberGenerator = new Random(System.currentTimeMillis());
final int notificationId = randomNumberGenerator.nextInt();
Voice.handleMessage(this, data, new MessageListener() {
@Override
public void onCallInvite(final CallInvite callInvite) {
// We need to run this on the main thread, as the React code assumes that is true.
// Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
// "Can't create handler inside thread that has not called Looper.prepare()"
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
// Construct and load our normal React JS code bundle
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notification
if (context != null) {
int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext) context);
if (BuildConfig.DEBUG) {
Log.d(TAG, "CONTEXT present appImportance = " + appImportance);
}
Intent launchIntent = callNotificationManager.getLaunchIntent((ReactApplicationContext) context, notificationId, callInvite, false, appImportance);
// app is not in foreground
if (appImportance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
context.startActivity(launchIntent);
}
VoiceFirebaseMessagingService.this.handleIncomingCall((ReactApplicationContext) context, notificationId, callInvite, launchIntent);
} else {
// Otherwise wait for construction, then handle the incoming call
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext context) {
int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext) context);
if (BuildConfig.DEBUG) {
Log.d(TAG, "CONTEXT not present appImportance = " + appImportance);
}
Intent launchIntent = callNotificationManager.getLaunchIntent((ReactApplicationContext) context, notificationId, callInvite, true, appImportance);
context.startActivity(launchIntent);
VoiceFirebaseMessagingService.this.handleIncomingCall((ReactApplicationContext) context, notificationId, callInvite, launchIntent);
}
});
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// Construct it in the background
mReactInstanceManager.createReactContextInBackground();
}
}
}
});
}
@Override
public void onError(MessageException messageException) {
Log.e(TAG, "Error handling FCM message" + messageException.toString());
}
});
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
use of com.facebook.react.bridge.ReactApplicationContext in project react-native-push-notification by zo0r.
the class RNPushNotificationListenerService method onNewToken.
@Override
public void onNewToken(String token) {
final String deviceToken = token;
final FirebaseMessagingService serviceRef = (this.mFirebaseServiceDelegate == null) ? this : this.mFirebaseServiceDelegate;
Log.d(LOG_TAG, "Refreshed token: " + deviceToken);
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
// Construct and load our normal React JS code bundle
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) serviceRef.getApplication()).getReactNativeHost().getReactInstanceManager();
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notification
if (context != null) {
handleNewToken((ReactApplicationContext) context, deviceToken);
} else {
// Otherwise wait for construction, then send the notification
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext context) {
handleNewToken((ReactApplicationContext) context, deviceToken);
mReactInstanceManager.removeReactInstanceEventListener(this);
}
});
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// Construct it in the background
mReactInstanceManager.createReactContextInBackground();
}
}
}
});
}
Aggregations