Skip to content

Commit

Permalink
add getInterruptionFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
hubermat committed May 18, 2020
1 parent 167d9e6 commit 9e9655f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions RingerMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ export default class RingerMode {
return await RNRingerMode.getRingerMode();
return null;
}
static async getInterruptionFilter() {
if (Utils.isAndroid === true)
return await RNRingerMode.getInterruptionFilter();
return null;
}
}
31 changes: 29 additions & 2 deletions android/src/main/java/com/reactlibrary/RNRingerMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.reactlibrary;

import android.media.AudioManager;
import android.app.NotificationManager;
import android.content.Context;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand All @@ -17,7 +18,7 @@ public class RNRingerMode extends ReactContextBaseJavaModule {
private static final String VOL_MUSIC = "music";
private static final String VOL_ALARM = "alarm";
private static final String VOL_NOTIFICATION = "notification";

private final ReactApplicationContext reactContext;
private AudioManager am;

Expand Down Expand Up @@ -45,6 +46,32 @@ public void getRingerMode(Promise promise) {
case AudioManager.RINGER_MODE_VIBRATE:
promise.resolve("VIBRATE");
break;
default:
promise.resolve("UNKNOWN");
break;
}
}
}

@ReactMethod
public void getInterruptionFilter(Promise promise) {
int filter = NotificationManager.getCurrentInterruptionFilter();
switch(filter) {
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
promise.resolve("PRIORITY");
break;
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
promise.resolve("ALARMS");
break;
case NotificationManager.INTERRUPTION_FILTER_NONE:
promise.resolve("NONE");
break;
case NotificationManager.INTERRUPTION_FILTER_ALL:
promise.resolve("ALL");
break;
default:
promise.resolve("UNKNOWN");
break;
}
}

}

0 comments on commit 9e9655f

Please sign in to comment.