Skip to content

Commit 9407afd

Browse files
authored
fix: use getSystemService workaround for versions < Android 6 (#45)
1 parent f28f7af commit 9407afd

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

android/src/main/java/io/rumors/reactnativesettings/listeners/CaptioningChangeListener.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212

1313
import java.util.concurrent.CountDownLatch;
1414

15-
1615
public class CaptioningChangeListener extends CaptioningManager.CaptioningChangeListener {
1716
private Context mContext;
1817

1918
private CaptioningManager mCaptioningManager;
2019

2120
private CaptioningManager getCaptioningManager() {
22-
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
21+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
2322
return (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
2423
} else {
2524
// Android <= 5 bug workaround
@@ -28,19 +27,19 @@ private CaptioningManager getCaptioningManager() {
2827

2928
Handler handler = new Handler(Looper.getMainLooper());
3029
handler.post(new Runnable() {
31-
@Override
32-
public void run() {
33-
mCaptioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
34-
latch.countDown();
35-
}
30+
@Override
31+
public void run() {
32+
mCaptioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
33+
latch.countDown();
34+
}
3635
});
37-
36+
3837
try {
39-
latch.await();
38+
latch.await();
4039
} catch (InterruptedException e) {
41-
e.printStackTrace();
40+
e.printStackTrace();
4241
}
43-
42+
4443
return mCaptioningManager;
4544
}
4645
}

0 commit comments

Comments
 (0)