com.facebook.react.bridge.ReactApplicationContext#getApplicationContext ( )源码实例Demo

下面列出了com.facebook.react.bridge.ReactApplicationContext#getApplicationContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
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();
    }
}
 
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);
        }
    }
 
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();
}
 
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);
    }
}
 
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();
    }
}
 
源代码7 项目: react-native-fcm   文件: FIRMessagingModule.java
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();
}
 
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);
}
 
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);
        }
    }
 
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();
}
 
源代码11 项目: react-native-alarm-notification   文件: ANModule.java
ANModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mReactContext = reactContext;
    alarmUtil = new AlarmUtil((Application) reactContext.getApplicationContext());
}
 
源代码12 项目: react-native-get-sms-android   文件: SmsModule.java
public SmsModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mReactContext = reactContext;
    smsList = new HashMap<Long, String>();
    context = reactContext.getApplicationContext();
}
 
public ReactNativeHeadingModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mApplicationContext = reactContext.getApplicationContext();
}
 
public RNSimpleCompassModule(ReactApplicationContext reactContext) {
  super(reactContext);
  this.reactContext = reactContext;
  mApplicationContext = reactContext.getApplicationContext();
}
 
源代码15 项目: react-native-sqlite-storage   文件: SQLitePlugin.java
public SQLitePlugin(ReactApplicationContext reactContext) {
    super(reactContext);
    this.context = reactContext.getApplicationContext();
    this.threadPool = Executors.newCachedThreadPool();
}
 
源代码16 项目: react-native-sqlite-storage   文件: SQLitePlugin.java
public SQLitePlugin(ReactApplicationContext reactContext) {
    super(reactContext);
    this.context = reactContext.getApplicationContext();
    this.threadPool = Executors.newCachedThreadPool();
}