1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-26 20:04:42 +01:00

Check platform level before accessing field

This commit is contained in:
Fredrik Fornwall 2018-06-14 23:56:17 +02:00
parent dcd4626870
commit 6db81bfb7a

View File

@ -16,7 +16,12 @@ public class AudioAPI {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final String SampleRate = am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
final String framesPerBuffer = am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
final String AudioUnprocessed = am.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED);
final String AudioUnprocessed;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
AudioUnprocessed = am.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED);
} else {
AudioUnprocessed = null;
}
final int volume_level = am.getStreamVolume(AudioManager.STREAM_MUSIC);
final int maxvolume_level = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
final boolean bluetootha2dp = am.isBluetoothA2dpOn();
@ -74,7 +79,9 @@ public class AudioAPI {
out.beginObject();
out.name("PROPERTY_OUTPUT_SAMPLE_RATE").value(SampleRate);
out.name("PROPERTY_OUTPUT_FRAMES_PER_BUFFER").value(framesPerBuffer);
out.name("PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED").value(AudioUnprocessed);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
out.name("PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED").value(AudioUnprocessed);
}
out.name("STREAM_MUSIC_VOLUME").value(volume_level);
out.name("STREAM_MUSIC_MAXVOLUME").value(maxvolume_level);
out.name("BLUETOOTH_A2DP_IS_ON").value(bluetootha2dp);