下面列出了android.media.AudioManager#STREAM_NOTIFICATION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static String streamTypeToString(int stream) {
switch(stream) {
case AudioManager.STREAM_VOICE_CALL:
return "STREAM_VOICE_CALL";
case AudioManager.STREAM_MUSIC:
return "STREAM_MUSIC";
case AudioManager.STREAM_RING:
return "STREAM_RING";
case AudioManager.STREAM_ALARM:
return "STREAM_ALARM";
case AudioManager.STREAM_NOTIFICATION:
return "STREAM_NOTIFICATION";
case AudioManager.STREAM_SYSTEM:
return "STREAM_SYSTEM";
default:
return "STREAM_INVALID";
}
}
private static String streamTypeToString(int stream) {
switch (stream) {
case AudioManager.STREAM_VOICE_CALL:
return "STREAM_VOICE_CALL";
case AudioManager.STREAM_MUSIC:
return "STREAM_MUSIC";
case AudioManager.STREAM_RING:
return "STREAM_RING";
case AudioManager.STREAM_ALARM:
return "STREAM_ALARM";
case AudioManager.STREAM_NOTIFICATION:
return "STREAM_NOTIFICATION";
case AudioManager.STREAM_SYSTEM:
return "STREAM_SYSTEM";
default:
return "STREAM_INVALID";
}
}
@Override
public void onCodeScanned(String contents) {
Log.d(TAG, "Code Scanned: " + contents);
if (isCodeAlreadyScanned) {
return;
} // To avoid double scans and pop 2 times the fragment
isCodeAlreadyScanned = true;
// Beep
final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
//
mListener.onPasswordUpdated(contents);
// Pop current fragment
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
fragmentManager.popBackStack();
}
}
@Override protected int[] getStreamIcons(StreamControl sc) {
if (sc.streamType == STREAM_BLUETOOTH_SCO)
return new int[] { R.drawable.oppo_ic_audio_bt, R.drawable.oppo_ic_audio_bt_mute };
switch (sc.streamType) {
case AudioManager.STREAM_ALARM:
return new int[] { R.drawable.oppo_ic_audio_alarm, R.drawable.oppo_ic_audio_alarm_mute };
case AudioManager.STREAM_RING:
return new int[] { R.drawable.oppo_ic_audio_ring_notif, R.drawable.oppo_ic_audio_ring_notif_mute };
case AudioManager.STREAM_NOTIFICATION:
return new int[] { R.drawable.oppo_ic_audio_notification, R.drawable.oppo_ic_audio_notification_mute };
case AudioManager.STREAM_MUSIC:
return new int[] { R.drawable.oppo_ic_audio_media, R.drawable.oppo_ic_audio_media_mute };
case AudioManager.STREAM_VOICE_CALL:
return new int[] { R.drawable.oppo_ic_audio_phone, R.drawable.oppo_ic_audio_phone };
default:
return new int[] { R.drawable.oppo_ic_audio_vol, R.drawable.oppo_ic_audio_vol_mute };
}
}
private int getAudioOutput() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_MUSIC");
if("STREAM_VOICE_CALL".equals(value)) {
return AudioManager.STREAM_VOICE_CALL;
} else if("STREAM_SYSTEM".equals(value)) {
return AudioManager.STREAM_SYSTEM;
} else if("STREAM_RING".equals(value)) {
return AudioManager.STREAM_RING;
} else if("STREAM_MUSIC".equals(value)) {
return AudioManager.STREAM_MUSIC;
} else if("STREAM_ALARM".equals(value)) {
return AudioManager.STREAM_ALARM;
} else if("STREAM_NOTIFICATION".equals(value)) {
return AudioManager.STREAM_NOTIFICATION;
} else if("STREAM_DTMF".equals(value)) {
return AudioManager.STREAM_DTMF;
} else {
return AudioManager.STREAM_RING;
}
}
@Override
public void onRingerModeChange(int ringerMode) {
super.onRingerModeChange(ringerMode);
if (null != mLastVolumeChange) {
switch (mLastVolumeChange.mStreamType) {
case AudioManager.STREAM_NOTIFICATION:
case AudioManager.STREAM_RING:
switch (ringerMode) {
case RINGER_MODE_VIBRATE:
icon.setImageResource(getVibrateIcon());
break;
case RINGER_MODE_SILENT:
default:
icon.setImageResource(getSilentIcon());
break;
}
break;
}
}
}
protected int[] _getStreamIcons(StreamControl sc) {
int[] icons = getStreamIcons(sc);
if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
sc.streamType == AudioManager.STREAM_RING) {
switch (mRingerMode) {
case AudioManager.RINGER_MODE_VIBRATE:
icons[1] = getVibrateIcon();
break;
case AudioManager.RINGER_MODE_SILENT:
icons[1] = getSilentIcon();
break;
}
}
return icons;
}
private void muteVolume() {
int[] volumes = new int[]{AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_SYSTEM, AudioManager.STREAM_RING, AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION};
for (int volumeType : volumes) {
audio.setStreamMute(volumeType, true);
}
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
}
private void applySound(Notification notification) {
if (sound == null) {
notification.sound = null;
} else {
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
notification.sound = Uri.parse(sound);
}
}
@Override
public void onCodeScanned(String contents) {
Log.d(TAG, "Code Scanned: " + contents);
// Beep
final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
//
Intent data = new Intent();
data.putExtra(kActivityResult_ScannedContents, contents);
setResult(RESULT_OK, data);
finish();
}
public MessagesController() {
MessagesStorage storage = MessagesStorage.getInstance();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("fons_size", 16);
try {
soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
sound = soundPool.load(ApplicationLoader.applicationContext, R.raw.electronic, 1);
} catch (Exception e) {
FileLog.e("yahala", e);
}
}
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "OnCreate");
toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
// Location Update PI
Intent locationUpdateIntent = new Intent(Constants.LOCATION_UPDATE);
locationUpdatePI = PendingIntent.getBroadcast(this, 9001, locationUpdateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
registerReceiver(locationUpdateReceiver, new IntentFilter(Constants.LOCATION_UPDATE));
Intent detectedActivitiesIntent = new Intent(Constants.DETECTED_ACTIVITY_UPDATE);
detectedActivitiesPI = PendingIntent.getBroadcast(this, 9002, detectedActivitiesIntent, PendingIntent.FLAG_UPDATE_CURRENT);
registerReceiver(detectedActivitiesReceiver, new IntentFilter(Constants.DETECTED_ACTIVITY_UPDATE));
// Receivers for start/stop recording
registerReceiver(startRecordingReceiver, new IntentFilter(Constants.START_RECORDING));
registerReceiver(stopRecordingReceiver, new IntentFilter(Constants.STOP_RECORDING));
registerReceiver(startAggressiveReceiver, new IntentFilter(Constants.CHANGE_AGGRESSIVE));
// Location criteria
criteria = new Criteria();
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
}
boolean updateRingerModeAffectedStreams(Context context) {
int ringerModeAffectedStreams;
// make sure settings for ringer mode are consistent with device type: non voice capable
// devices (tablets) include media stream in silent mode whereas phones don't.
ringerModeAffectedStreams = Settings.System.getInt(context.getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED,
((1 << AudioManager.STREAM_RING)|(1 << AudioManager.STREAM_NOTIFICATION)|
(1 << AudioManager.STREAM_SYSTEM)));
// ringtone, notification and system streams are always affected by ringer mode
ringerModeAffectedStreams |= (1 << AudioManager.STREAM_RING)|
(1 << AudioManager.STREAM_NOTIFICATION)|
(1 << AudioManager.STREAM_SYSTEM);
if (mVoiceCapable) {
ringerModeAffectedStreams &= ~(1 << AudioManager.STREAM_MUSIC);
} else {
ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
}
if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
mRingerModeAffectedStreams = ringerModeAffectedStreams;
return true;
}
return false;
}
public SoundHelper(Context context){
mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
soundIdRedEnvelopeComing = mSoundPool.load(context, R.raw.red_envelope_coming, 1);
}
private boolean isValidLocalStreamType(int streamType) {
return streamType >= AudioManager.STREAM_VOICE_CALL
&& streamType <= AudioManager.STREAM_NOTIFICATION;
}
private static boolean isNotificationOrRing(int stream) {
return stream == AudioManager.STREAM_RING || stream == AudioManager.STREAM_NOTIFICATION;
}
@Override
public void onCreate() {
toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
}
/**
* Default Constructor.
*/
public HUDFragment() {
toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
}
/**
* Loads the default volume levels. It is actually inserting the index of
* the volume array for each of the volume controls.
*
* @param db the database to insert the volume levels into
*/
private void loadVolumeLevels(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_MUSIC,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
loadSetting(stmt, Settings.System.VOLUME_RING,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
loadSetting(
stmt,
Settings.System.VOLUME_VOICE,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
loadSetting(stmt, Settings.System.VOLUME_ALARM,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
loadSetting(
stmt,
Settings.System.VOLUME_NOTIFICATION,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
loadSetting(
stmt,
Settings.System.VOLUME_BLUETOOTH_SCO,
AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
// By default:
// - ringtones, notification, system and music streams are affected by ringer mode
// on non voice capable devices (tablets)
// - ringtones, notification and system streams are affected by ringer mode
// on voice capable devices (phones)
int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
(1 << AudioManager.STREAM_NOTIFICATION) |
(1 << AudioManager.STREAM_SYSTEM) |
(1 << AudioManager.STREAM_SYSTEM_ENFORCED);
if (!mContext.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable)) {
ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
}
loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
ringerModeAffectedStreams);
loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
((1 << AudioManager.STREAM_MUSIC) |
(1 << AudioManager.STREAM_RING) |
(1 << AudioManager.STREAM_NOTIFICATION) |
(1 << AudioManager.STREAM_SYSTEM)));
} finally {
if (stmt != null) stmt.close();
}
loadVibrateWhenRingingSetting(db);
}
/**
* Loads the default volume levels. It is actually inserting the index of
* the volume array for each of the volume controls.
*
* @param db the database to insert the volume levels into
*/
private void loadVolumeLevels(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_MUSIC,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
loadSetting(stmt, Settings.System.VOLUME_RING,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
loadSetting(
stmt,
Settings.System.VOLUME_VOICE,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
loadSetting(stmt, Settings.System.VOLUME_ALARM,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
loadSetting(
stmt,
Settings.System.VOLUME_NOTIFICATION,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
loadSetting(
stmt,
Settings.System.VOLUME_BLUETOOTH_SCO,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
// By default:
// - ringtones, notification, system and music streams are affected by ringer mode
// on non voice capable devices (tablets)
// - ringtones, notification and system streams are affected by ringer mode
// on voice capable devices (phones)
int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
(1 << AudioManager.STREAM_NOTIFICATION) |
(1 << AudioManager.STREAM_SYSTEM) |
(1 << AudioManager.STREAM_SYSTEM_ENFORCED);
if (!mContext.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable)) {
ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
}
loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
ringerModeAffectedStreams);
loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
} finally {
if (stmt != null) stmt.close();
}
loadVibrateWhenRingingSetting(db);
}