Example usage for android.media AudioManager STREAM_NOTIFICATION

List of usage examples for android.media AudioManager STREAM_NOTIFICATION

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_NOTIFICATION.

Prototype

int STREAM_NOTIFICATION

To view the source code for android.media AudioManager STREAM_NOTIFICATION.

Click Source Link

Document

Used to identify the volume of audio streams for notifications

Usage

From source file:Main.java

/** Returns the volume for notifications. */
public static int getNotificationVolume(Context context) {
    AudioManager am = getAudioManager(context);
    return am.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
}

From source file:Main.java

public static void playSound(Context context, Uri uri) {
    final MediaPlayer player = new MediaPlayer();
    try {/*ww w.  j a va2s.  c  o m*/
        player.setDataSource(context.getApplicationContext(), uri);
        player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
        player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.start();
            }
        });
        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                player.release();
            }
        });
        player.prepareAsync();
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void playNotificationSound(Context context) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        Ringtone rt = RingtoneManager.getRingtone(context, uri);
        if (rt != null) {
            rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
            rt.play();//  w ww  .j  ava  2s .com
        }
    }
}

From source file:Main.java

public static void setAudioManage(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
}

From source file:com.marianhello.bgloc.AbstractLocationProvider.java

public void onCreate() {
    toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
}

From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationProvider.java

public void onCreate() {
    toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);

    handlerThread = new HandlerThread("LocationProviderThread");
    handlerThread.start();//from w  ww.  ja  v a2  s.  c o  m
}

From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java

@Override
public void onCreate() {
    super.onCreate();
    toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
}

From source file:edu.northwestern.cbits.activitydetector.app.MainActivity.java

private void UpdateGUI() {
    i++;/*from  www  . java2  s. com*/

    final MainActivity me = this;

    // Runs once a second
    mHandler.post(new Runnable() {
        public void run() {
            Log.d(getString(R.string.app_name), ActivityRecognitionIntentService.ACTIVITY_NAME);
            nameView.setText(
                    ActivityRecognitionIntentService.ACTIVITY_NAME + " " + System.currentTimeMillis() / 1000);

            //setting up tone for on_foot
            Uri defaultRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            MediaPlayer mediaPlayer = new MediaPlayer();

            try {
                mediaPlayer.setDataSource(me, defaultRingtoneUri);
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
                mediaPlayer.prepare();
                mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        mp.release();
                    }
                });

                if (ActivityRecognitionIntentService.ACTIVITY_NAME == "on_foot") {
                    mediaPlayer.start();
                } else {
                    mediaPlayer.release();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            ;
        }
    });
}

From source file:com.google.android.car.kitchensink.volume.VolumeTestFragment.java

private static String streamToName(int stream) {
    switch (stream) {
    case AudioManager.STREAM_ALARM:
        return "Alarm";
    case AudioManager.STREAM_MUSIC:
        return "Music";
    case AudioManager.STREAM_NOTIFICATION:
        return "Notification";
    case AudioManager.STREAM_RING:
        return "Ring";
    case AudioManager.STREAM_VOICE_CALL:
        return "Call";
    case AudioManager.STREAM_SYSTEM:
        return "System";
    default:/*from  www  .j  a  v a2  s  . c o m*/
        return "Unknown";
    }
}

From source file:com.unlockdisk.android.opengl.MainGLActivity.java

public void generateNotification(int id, String notificationTitle, String notificationMessage) {
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, "A New Message!",
            System.currentTimeMillis());

    Intent notificationIntent = new Intent(this, MainGLActivity.class);
    // Intent notificationIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(MainGLActivity.this, notificationTitle, notificationMessage, pendingIntent);

    //Setting Notification Flags
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.DEFAULT_SOUND;
    //Adding the Custom Sound
    notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
    String uri = "android.resource://org.openmobster.notify.android.app/"
            + MainGLActivity.this.findSoundId(MainGLActivity.this, "beep");
    notification.sound = Uri.parse(uri);
    //  notification.sound = Uri.fromFile(new File(R.raw.a));
    notificationManager.notify(id, notification);
}