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

The following examples show how to use com.facebook.react.bridge.ReactApplicationContext#getSystemService() . 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: RNInvokeApp.java    From react-native-invoke-app with MIT License 6 votes vote down vote up
private boolean isAppOnForeground(ReactApplicationContext context) {
    /**
     * We need to check if app is in foreground otherwise the app will crash.
     * http://stackoverflow.com/questions/8489993/check-android-application-is-in-foreground-or-not
     **/
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        return false;
    }
    final String packageName = context.getPackageName();
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
                && appProcess.processName.equals(packageName)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.M)
public void testFingerprintAvailableButNotConfigured_api23() throws Exception {
  // GIVEN:
  //   fingerprint api available but not configured properly
  //   API23 android version
  ReactApplicationContext context = getRNContext();
  KeychainModule module = new KeychainModule(context);

  // set that hardware is available
  FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);

  // WHEN: check availability
  final int result = BiometricManager.from(context).canAuthenticate();
  final boolean isFingerprintWorking = module.isFingerprintAuthAvailable();

  // THEN: another status from biometric api, fingerprint is still unavailable
  assertThat(result, is(BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED));
  assertThat(isFingerprintWorking, is(false));
}
 
Example 3
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testFingerprintConfigured_api28() throws Exception {
  // GIVEN:
  //   API28 android version
  //   for api24+ system feature should be enabled
  //   fingerprints are configured
  ReactApplicationContext context = getRNContext();
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available
  FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  // WHEN: verify availability
  final int result = BiometricManager.from(context).canAuthenticate();
  final KeychainModule module = new KeychainModule(context);
  final boolean isFingerprintWorking = module.isFingerprintAuthAvailable();

  // THEN: biometrics works
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));
  assertThat(isFingerprintWorking, is(true));
}
 
Example 4
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
public InCallManagerModule(ReactApplicationContext reactContext) {
    super(reactContext);
    mPackageName = reactContext.getPackageName();
    reactContext.addLifecycleEventListener(this);
    mWindowManager = (WindowManager) reactContext.getSystemService(Context.WINDOW_SERVICE);
    mPowerManager = (PowerManager) reactContext.getSystemService(Context.POWER_SERVICE);
    audioManager = ((AudioManager) reactContext.getSystemService(Context.AUDIO_SERVICE));
    audioUriMap = new HashMap<String, Uri>();
    audioUriMap.put("defaultRingtoneUri", defaultRingtoneUri);
    audioUriMap.put("defaultRingbackUri", defaultRingbackUri);
    audioUriMap.put("defaultBusytoneUri", defaultBusytoneUri);
    audioUriMap.put("bundleRingtoneUri", bundleRingtoneUri);
    audioUriMap.put("bundleRingbackUri", bundleRingbackUri);
    audioUriMap.put("bundleBusytoneUri", bundleBusytoneUri);
    mRequestPermissionCodePromises = new SparseArray<Promise>();
    mRequestPermissionCodeTargetPermission = new SparseArray<String>();
    mOnFocusChangeListener = new OnFocusChangeListener();
    bluetoothManager = AppRTCBluetoothManager.create(reactContext, this);
    proximityManager = InCallProximityManager.create(reactContext, this);
    wakeLockUtils = new InCallWakeLockUtils(reactContext);

    Log.d(TAG, "InCallManager initialized");
}
 
Example 5
Source File: CipherStorageKeystoreRsaEcbTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testVerifySecureHardwareAvailability_api28() throws Exception {
  ReactApplicationContext context = getRNContext();

  // for api24+ system feature should be enabled
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available and fingerprints configured
  final FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  int result = BiometricManager.from(context).canAuthenticate();
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));

  final CipherStorage storage = new CipherStorageKeystoreAesCbc();;

  // expected RsaEcb with fingerprint
  assertThat(storage.supportsSecureHardware(), is(true));
}
 
Example 6
Source File: MusicControlModule.java    From react-native-music-control with MIT License 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel(ReactApplicationContext context) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, "Media playback", NotificationManager.IMPORTANCE_LOW);
    mChannel.setDescription("Media playback controls");
    mChannel.setShowBadge(false);
    mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    mNotificationManager.createNotificationChannel(mChannel);
}
 
Example 7
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testExtractRsaEcb_EnabledFingerprint_api28() throws Exception {
  // GIVEN:
  //   API28 android version
  //   fingerprint feature enabled
  //   fingerprints configured
  final ReactApplicationContext context = getRNContext();
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available and fingerprints configured
  final FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  // WHEN: get secured storage
  final int result = BiometricManager.from(context).canAuthenticate();
  final KeychainModule module = new KeychainModule(context);
  final boolean isFingerprintWorking = module.isFingerprintAuthAvailable();
  final CipherStorage storage = module.getCipherStorageForCurrentAPILevel();

  // THEN: expected RsaEcb with working fingerprint
  assertThat(isFingerprintWorking, is(true));
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));
  assertThat(storage, notNullValue());
  assertThat(storage, instanceOf(CipherStorageKeystoreRsaEcb.class));
  assertThat(storage.isBiometrySupported(), is(true));
  assertThat(storage.securityLevel(), is(SecurityLevel.SECURE_HARDWARE));
  assertThat(storage.getMinSupportedApiLevel(), is(Build.VERSION_CODES.M));
  assertThat(storage.supportsSecureHardware(), is(true));
}
 
Example 8
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.M)
public void testExtractRsaEcb_EnabledFingerprint_api23() throws Exception {
  // GIVEN:
  //   API23 android version
  //   fingerprints configured
  final ReactApplicationContext context = getRNContext();

  // set that hardware is available and fingerprints configured
  final FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  // WHEN: fingerprint availability influence on storage selection
  final KeychainModule module = new KeychainModule(context);
  final boolean isFingerprintWorking = module.isFingerprintAuthAvailable();
  final CipherStorage storage = module.getCipherStorageForCurrentAPILevel();

  // THEN: expected RsaEcb with working fingerprint
  assertThat(isFingerprintWorking, is(true));
  assertThat(storage, notNullValue());
  assertThat(storage, instanceOf(CipherStorageKeystoreRsaEcb.class));
  assertThat(storage.isBiometrySupported(), is(true));
  assertThat(storage.securityLevel(), is(SecurityLevel.SECURE_HARDWARE));
  assertThat(storage.getMinSupportedApiLevel(), is(Build.VERSION_CODES.M));
  assertThat(storage.supportsSecureHardware(), is(true));
}
 
Example 9
Source File: ProximityManager.java    From react-native-twilio-programmable-voice with MIT License 5 votes vote down vote up
public ProximityManager(ReactApplicationContext context, EventManager em) {
    eventManager = em;
    powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    initProximityWakeLock();
}
 
Example 10
Source File: TwilioVoiceModule.java    From react-native-twilio-programmable-voice with MIT License 5 votes vote down vote up
public TwilioVoiceModule(ReactApplicationContext reactContext,
boolean shouldAskForMicPermission) {
    super(reactContext);
    if (BuildConfig.DEBUG) {
        Voice.setLogLevel(LogLevel.DEBUG);
    } else {
        Voice.setLogLevel(LogLevel.ERROR);
    }
    reactContext.addActivityEventListener(this);
    reactContext.addLifecycleEventListener(this);

    eventManager = new EventManager(reactContext);
    callNotificationManager = new CallNotificationManager();
    proximityManager = new ProximityManager(reactContext, eventManager);
    headsetManager = new HeadsetManager(eventManager);

    notificationManager = (android.app.NotificationManager) reactContext.getSystemService(Context.NOTIFICATION_SERVICE);

    /*
     * Setup the broadcast receiver to be notified of GCM Token updates
     * or incoming call messages in this Activity.
     */
    voiceBroadcastReceiver = new VoiceBroadcastReceiver();
    registerReceiver();

    TwilioVoiceModule.callNotificationMap = new HashMap<>();

    /*
     * Needed for setting/abandoning audio focus during a call
     */
    audioManager = (AudioManager) reactContext.getSystemService(Context.AUDIO_SERVICE);

    /*
     * Ensure the microphone permission is enabled
     */
    if (shouldAskForMicPermission && !checkPermissionForMicrophone()) {
        requestPermissionForMicrophone();
    }
}
 
Example 11
Source File: RNSensitiveInfoModule.java    From react-native-sensitive-info with MIT License 5 votes vote down vote up
public RNSensitiveInfoModule(ReactApplicationContext reactContext) {
    super(reactContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        try {
            mFingerprintManager = (FingerprintManager) reactContext.getSystemService(Context.FINGERPRINT_SERVICE);
        } catch (Exception e) {
            Log.d("RNSensitiveInfo", "Fingerprint not supported");
        }
        initKeyStore();
    }
}
 
Example 12
Source File: RNOS.java    From react-native-os with MIT License 5 votes vote down vote up
public RNOS(ReactApplicationContext reactContext) {
    super(reactContext);
    mConnectivityManager =
            (ConnectivityManager) reactContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    mConnectivityBroadcastReceiver = new ConnectivityBroadcastReceiver();

    reactContext.addLifecycleEventListener(this);
}
 
Example 13
Source File: GPSStateModule.java    From react-native-gps-state with MIT License 5 votes vote down vote up
public GPSStateModule(ReactApplicationContext reactContext) {
    super(reactContext);
    locationManager = (LocationManager) reactContext.getSystemService(reactContext.LOCATION_SERVICE);

    try {
        final PackageInfo info = reactContext.getPackageManager().getPackageInfo(reactContext.getPackageName(), 0);
        targetSdkVersion = info.applicationInfo.targetSdkVersion;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source File: MainReactPackageWithFrescoCache.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
private Supplier<MemoryCacheParams> createCacheParamsSupplier(
  final ReactApplicationContext context
) {
  ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  final Supplier<MemoryCacheParams> cacheParamsSupplier =
    new DefaultBitmapMemoryCacheParamsSupplier(manager) {
      @Override
      public MemoryCacheParams get() {
        MemoryCacheParams params = super.get();

        return new MemoryCacheParams(
          mMaxCacheSizeInBytes == null ? params.maxCacheSize : mMaxCacheSizeInBytes,
          mMaxCacheEntries == null ? params.maxCacheEntries : mMaxCacheEntries,
          params.maxEvictionQueueSize,
          params.maxEvictionQueueEntries,
          params.maxCacheEntrySize
        );
      }
    };

  String size = String.valueOf(cacheParamsSupplier.get().maxCacheSize / 1024 / 1024);
  String entries = String.valueOf(cacheParamsSupplier.get().maxCacheEntries);
  FLog.d(
    ReactConstants.TAG,
    "ImageFilterKit: Fresco cache size - " + entries + " entries, " + size + " MB overall"
  );

  return cacheParamsSupplier;
}
 
Example 15
Source File: RNExitAppModule.java    From react-native-exit-app with MIT License 4 votes vote down vote up
public RNExitAppModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
    alarmManager = (AlarmManager) reactContext.getSystemService(Context.ALARM_SERVICE);
}
 
Example 16
Source File: RNLocalNotificationsModule.java    From react-native-local-notifications with MIT License 4 votes vote down vote up
public RNLocalNotificationsModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
    alarmManager = (AlarmManager) reactContext.getSystemService(Context.ALARM_SERVICE);
}
 
Example 17
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void createIncomingCallNotification(ReactApplicationContext context,
                                           CallInvite callInvite,
                                           int notificationId,
                                           Intent launchIntent)
{
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "createIncomingCallNotification intent "+launchIntent.getFlags());
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    /*
     * Pass the notification id and call sid to use as an identifier to cancel the
     * notification later
     */
    Bundle extras = new Bundle();
    extras.putInt(INCOMING_CALL_NOTIFICATION_ID, notificationId);
    extras.putString(CALL_SID_KEY, callInvite.getCallSid());
    extras.putString(NOTIFICATION_TYPE, ACTION_INCOMING_CALL);
    /*
     * Create the notification shown in the notification drawer
     */
    initCallNotificationsChannel(notificationManager);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(context, VOICE_CHANNEL)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setSmallIcon(R.drawable.ic_call_white_24dp)
                    .setContentTitle("Incoming call")
                    .setContentText(callInvite.getFrom() + " is calling")
                    .setOngoing(true)
                    .setAutoCancel(true)
                    .setExtras(extras)
                    .setFullScreenIntent(pendingIntent, true);

    // build notification large icon
    Resources res = context.getResources();
    int largeIconResId = res.getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (largeIconResId != 0) {
            notificationBuilder.setLargeIcon(largeIconBitmap);
        }
    }

    // Reject action
    Intent rejectIntent = new Intent(ACTION_REJECT_CALL)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingRejectIntent = PendingIntent.getBroadcast(context, 1, rejectIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(0, "DISMISS", pendingRejectIntent);

    // Answer action
    Intent answerIntent = new Intent(ACTION_ANSWER_CALL);
    answerIntent
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAnswerIntent = PendingIntent.getBroadcast(context, 0, answerIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.addAction(R.drawable.ic_call_white_24dp, "ANSWER", pendingAnswerIntent);

    notificationManager.notify(notificationId, notificationBuilder.build());
    TwilioVoiceModule.callNotificationMap.put(INCOMING_NOTIFICATION_PREFIX+callInvite.getCallSid(), notificationId);
}
 
Example 18
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void createMissedCallNotification(ReactApplicationContext context, CallInvite callInvite) {
    SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCE_KEY, Context.MODE_PRIVATE);
    SharedPreferences.Editor sharedPrefEditor = sharedPref.edit();

    /*
     * Create a PendingIntent to specify the action when the notification is
     * selected in the notification drawer
     */
    Intent intent = new Intent(context, getMainActivityClass(context));
    intent.setAction(ACTION_MISSED_CALL)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, MISSED_CALLS_NOTIFICATION_ID)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent clearMissedCallsCountIntent = new Intent(ACTION_CLEAR_MISSED_CALLS_COUNT)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, CLEAR_MISSED_CALLS_NOTIFICATION_ID);
    PendingIntent clearMissedCallsCountPendingIntent = PendingIntent.getBroadcast(context, 0, clearMissedCallsCountIntent, 0);
    /*
     * Pass the notification id and call sid to use as an identifier to open the notification
     */
    Bundle extras = new Bundle();
    extras.putInt(INCOMING_CALL_NOTIFICATION_ID, MISSED_CALLS_NOTIFICATION_ID);
    extras.putString(CALL_SID_KEY, callInvite.getCallSid());
    extras.putString(NOTIFICATION_TYPE, ACTION_MISSED_CALL);

    /*
     * Create the notification shown in the notification drawer
     */
    NotificationCompat.Builder notification =
            new NotificationCompat.Builder(context, VOICE_CHANNEL)
                    .setGroup(MISSED_CALLS_GROUP)
                    .setGroupSummary(true)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setSmallIcon(R.drawable.ic_call_missed_white_24dp)
                    .setContentTitle("Missed call")
                    .setContentText(callInvite.getFrom() + " called")
                    .setAutoCancel(true)
                    .setShowWhen(true)
                    .setExtras(extras)
                    .setDeleteIntent(clearMissedCallsCountPendingIntent)
                    .setContentIntent(pendingIntent);

    int missedCalls = sharedPref.getInt(MISSED_CALLS_GROUP, 0);
    missedCalls++;
    if (missedCalls == 1) {
        inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle("Missed call");
    } else {
        inboxStyle.setBigContentTitle(String.valueOf(missedCalls) + " missed calls");
    }
    inboxStyle.addLine("from: " +callInvite.getFrom());
    sharedPrefEditor.putInt(MISSED_CALLS_GROUP, missedCalls);
    sharedPrefEditor.commit();

    notification.setStyle(inboxStyle);

    // build notification large icon
    Resources res = context.getResources();
    int largeIconResId = res.getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && largeIconResId != 0) {
        notification.setLargeIcon(largeIconBitmap);
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(MISSED_CALLS_NOTIFICATION_ID, notification.build());
}
 
Example 19
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void createHangupLocalNotification(ReactApplicationContext context, String callSid, String caller) {
    PendingIntent pendingHangupIntent = PendingIntent.getBroadcast(
            context,
            0,
            new Intent(ACTION_HANGUP_CALL).putExtra(INCOMING_CALL_NOTIFICATION_ID, HANGUP_NOTIFICATION_ID),
            PendingIntent.FLAG_UPDATE_CURRENT
    );
    Intent launchIntent = new Intent(context, getMainActivityClass(context));
    launchIntent.setAction(ACTION_INCOMING_CALL)
            .putExtra(INCOMING_CALL_NOTIFICATION_ID, HANGUP_NOTIFICATION_ID)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    /*
     * Pass the notification id and call sid to use as an identifier to cancel the
     * notification later
     */
    Bundle extras = new Bundle();
    extras.putInt(INCOMING_CALL_NOTIFICATION_ID, HANGUP_NOTIFICATION_ID);
    extras.putString(CALL_SID_KEY, callSid);
    extras.putString(NOTIFICATION_TYPE, ACTION_HANGUP_CALL);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context, VOICE_CHANNEL)
            .setContentTitle("Call in progress")
            .setContentText(caller)
            .setSmallIcon(R.drawable.ic_call_white_24dp)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_CALL)
            .setOngoing(true)
            .setUsesChronometer(true)
            .setExtras(extras)
            .setContentIntent(activityPendingIntent);

    notification.addAction(0, "HANG UP", pendingHangupIntent);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Create notifications channel (required for API > 25)
    initCallNotificationsChannel(notificationManager);
    notificationManager.notify(HANGUP_NOTIFICATION_ID, notification.build());
}
 
Example 20
Source File: CallNotificationManager.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void removeHangupNotification(ReactApplicationContext context) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(HANGUP_NOTIFICATION_ID);
}