Java Code Examples for com.facebook.react.bridge.ReactApplicationContext#getApplicationContext()

The following examples show how to use com.facebook.react.bridge.ReactApplicationContext#getApplicationContext() . 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: RNPushNotificationPublisher.java    From react-native-push-notification-CE with MIT License 6 votes vote down vote up
private boolean isApplicationInForeground(ReactApplicationContext context) {
                    ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
                    List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
                    if (processInfos != null) {
                        for (RunningAppProcessInfo processInfo : processInfos) {
                        Application applicationContext = (Application) context.getApplicationContext();
                            if (processInfo.processName.equals(applicationContext.getPackageName())) {
                                if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                                    for (String d : processInfo.pkgList) {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                    
            return false;
}
 
Example 2
Source File: ActivityRecognizer.java    From react-native-activity-recognition with GNU General Public License v2.0 6 votes vote down vote up
public ActivityRecognizer(ReactApplicationContext reactContext) {
    mGoogleApiAvailability = GoogleApiAvailability.getInstance();
    mContext = reactContext.getApplicationContext();
    mReactContext = reactContext;
    connected = false;
    started = false;

    if (checkPlayServices()) {
        mBroadcastReceiver = new ActivityDetectionBroadcastReceiver();
        mGoogleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(ActivityRecognition.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    }
}
 
Example 3
Source File: RNPushNotificationPublisher.java    From react-native-push-notification-CE with MIT License 5 votes vote down vote up
private void handleLocalNotification(ReactApplicationContext context, Bundle bundle) {

        // If notification ID is not provided by the user for push notification, generate one at random
        if (bundle.getString("id") == null) {
            Random randomNumberGenerator = new Random(System.currentTimeMillis());
            bundle.putString("id", String.valueOf(randomNumberGenerator.nextInt()));
        }

        Boolean isForeground = isApplicationInForeground(context);

        RNPushNotificationJsDelivery jsDelivery = new RNPushNotificationJsDelivery(context);
        bundle.putBoolean("foreground", isForeground);
        jsDelivery.notifyNotification(bundle);

        // If contentAvailable is set to true, then send out a remote fetch event
        if (bundle.getString("contentAvailable", "false").equalsIgnoreCase("true")) {
            jsDelivery.notifyRemoteFetch(bundle);
        }

        Log.v(LOG_TAG, "sendNotification: " + bundle);

        if (!isForeground) {
            Application applicationContext = (Application) context.getApplicationContext();
            RNPushNotificationHelper pushNotificationHelper = new RNPushNotificationHelper(applicationContext);
            pushNotificationHelper.sendToNotificationCentre(bundle);
        }
    }
 
Example 4
Source File: RNPushNotification.java    From react-native-push-notification-CE with MIT License 5 votes vote down vote up
public RNPushNotification(ReactApplicationContext reactContext) {
    super(reactContext);

    reactContext.addActivityEventListener(this);

    Application applicationContext = (Application) reactContext.getApplicationContext();
    // The @ReactNative methods use this
    mRNPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
    // This is used to delivery callbacks to JS
    mJsDelivery = new RNPushNotificationJsDelivery(reactContext);

    registerNotificationsRegistration();
}
 
Example 5
Source File: RNPushNotificationListenerService.java    From react-native-push-notification-CE with MIT License 5 votes vote down vote up
private void handleRemotePushNotification(ReactApplicationContext context, Bundle bundle) {
    // If notification ID is not provided by the user for push notification, generate one at random
    if (bundle.getString("id") == null) {
        Random randomNumberGenerator = new Random(System.currentTimeMillis());
        bundle.putString("id", String.valueOf(randomNumberGenerator.nextInt()));
    }

    Boolean isForeground = isApplicationInForeground();

    RNPushNotificationJsDelivery jsDelivery = new RNPushNotificationJsDelivery(context);
    bundle.putBoolean("foreground", isForeground);  
    jsDelivery.notifyNotification(bundle);

    // If contentAvailable is set to true, then send out a remote fetch event
    if (bundle.getString("contentAvailable", "false").equalsIgnoreCase("true")) {
        jsDelivery.notifyRemoteFetch(bundle);
    }

    Log.v(LOG_TAG, "sendNotification: " + bundle);

    String message = bundle.getString("message");
    if ((message != null && !message.isEmpty()) || !bundle.containsKey("content-available")) {
        Application applicationContext = (Application) context.getApplicationContext();
        RNPushNotificationHelper pushNotificationHelper = new RNPushNotificationHelper(applicationContext);
        pushNotificationHelper.sendToNotificationCentre(bundle);
    }
}
 
Example 6
Source File: AccessibilityInfoModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
public AccessibilityInfoModule(ReactApplicationContext context) {
    super(context);
    Context appContext = context.getApplicationContext();
    mAccessibilityManager = (AccessibilityManager) appContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    mEnabled = mAccessibilityManager.isTouchExplorationEnabled();
    if (Build.VERSION.SDK_INT >= 19) {
        mTouchExplorationStateChangeListener = new ReactTouchExplorationStateChangeListener();
    }
}
 
Example 7
Source File: FIRMessagingModule.java    From react-native-fcm with MIT License 5 votes vote down vote up
public FIRMessagingModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mFIRLocalMessagingHelper = new FIRLocalMessagingHelper((Application) reactContext.getApplicationContext());
    mBadgeHelper = new BadgeHelper(reactContext.getApplicationContext());
    getReactApplicationContext().addLifecycleEventListener(this);
    getReactApplicationContext().addActivityEventListener(this);
    registerTokenRefreshHandler();
    registerMessageHandler();
    registerLocalMessageHandler();
}
 
Example 8
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 5 votes vote down vote up
public BeaconsAndroidModule(ReactApplicationContext reactContext) {
    super(reactContext);
    Log.d(LOG_TAG, "BeaconsAndroidModule - started");
    this.mReactContext = reactContext;
    this.mApplicationContext = reactContext.getApplicationContext();
    this.mBeaconManager = BeaconManager.getInstanceForApplication(mApplicationContext);
    // Detect iBeacons ( http://stackoverflow.com/questions/25027983/is-this-the-correct-layout-to-detect-ibeacons-with-altbeacons-android-beacon-li )
    addParser("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24");
    mBeaconManager.bind(this);
}
 
Example 9
Source File: RNReceivedMessageHandler.java    From react-native-push-notification with MIT License 5 votes vote down vote up
private void handleRemotePushNotification(ReactApplicationContext context, Bundle bundle) {

        // If notification ID is not provided by the user for push notification, generate one at random
        if (bundle.getString("id") == null) {
            Random randomNumberGenerator = new Random(System.currentTimeMillis());
            bundle.putString("id", String.valueOf(randomNumberGenerator.nextInt()));
        }

        RNPushNotificationConfig config = new RNPushNotificationConfig(mFirebaseMessagingService.getApplication());

        Boolean isForeground = isApplicationInForeground();

        RNPushNotificationJsDelivery jsDelivery = new RNPushNotificationJsDelivery(context);
        bundle.putBoolean("foreground", isForeground);
        bundle.putBoolean("userInteraction", false);
        jsDelivery.notifyNotification(bundle);

        // If contentAvailable is set to true, then send out a remote fetch event
        if (bundle.getString("contentAvailable", "false").equalsIgnoreCase("true")) {
            jsDelivery.notifyRemoteFetch(bundle);
        }

        Log.v(LOG_TAG, "sendNotification: " + bundle);

        if (config.getNotificationForeground() || !isForeground) {
            Application applicationContext = (Application) context.getApplicationContext();
            RNPushNotificationHelper pushNotificationHelper = new RNPushNotificationHelper(applicationContext);
            pushNotificationHelper.sendToNotificationCentre(bundle);
        }
    }
 
Example 10
Source File: RNPushNotification.java    From react-native-push-notification with MIT License 5 votes vote down vote up
public RNPushNotification(ReactApplicationContext reactContext) {
    super(reactContext);

    reactContext.addActivityEventListener(this);

    Application applicationContext = (Application) reactContext.getApplicationContext();

    // The @ReactNative methods use this
    mRNPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
    // This is used to delivery callbacks to JS
    mJsDelivery = new RNPushNotificationJsDelivery(reactContext);

    mRNPushNotificationHelper.checkOrCreateDefaultChannel();
}
 
Example 11
Source File: ANModule.java    From react-native-alarm-notification with MIT License 4 votes vote down vote up
ANModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mReactContext = reactContext;
    alarmUtil = new AlarmUtil((Application) reactContext.getApplicationContext());
}
 
Example 12
Source File: SmsModule.java    From react-native-get-sms-android with MIT License 4 votes vote down vote up
public SmsModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mReactContext = reactContext;
    smsList = new HashMap<Long, String>();
    context = reactContext.getApplicationContext();
}
 
Example 13
Source File: ReactNativeHeadingModule.java    From react-native-heading with MIT License 4 votes vote down vote up
public ReactNativeHeadingModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mApplicationContext = reactContext.getApplicationContext();
}
 
Example 14
Source File: RNSimpleCompassModule.java    From react-native-simple-compass with MIT License 4 votes vote down vote up
public RNSimpleCompassModule(ReactApplicationContext reactContext) {
  super(reactContext);
  this.reactContext = reactContext;
  mApplicationContext = reactContext.getApplicationContext();
}
 
Example 15
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 4 votes vote down vote up
public SQLitePlugin(ReactApplicationContext reactContext) {
    super(reactContext);
    this.context = reactContext.getApplicationContext();
    this.threadPool = Executors.newCachedThreadPool();
}
 
Example 16
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 4 votes vote down vote up
public SQLitePlugin(ReactApplicationContext reactContext) {
    super(reactContext);
    this.context = reactContext.getApplicationContext();
    this.threadPool = Executors.newCachedThreadPool();
}