Example usage for android.media AudioManager FLAG_REMOVE_SOUND_AND_VIBRATE

List of usage examples for android.media AudioManager FLAG_REMOVE_SOUND_AND_VIBRATE

Introduction

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

Prototype

int FLAG_REMOVE_SOUND_AND_VIBRATE

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

Click Source Link

Document

Removes any sounds/vibrate that may be in the queue, or are playing (related to changing volume).

Usage

From source file:Main.java

private static void setVolume(AudioManager manager, int audioStream, int setValue) {
    int volume = manager.getStreamMaxVolume(audioStream) * setValue / 100;
    manager.setStreamVolume(audioStream, volume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}

From source file:Main.java

public static void adjustMusicVolume(Context context, boolean up, boolean showInterface) {
    int direction = up ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
    int flag = AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE | (showInterface ? AudioManager.FLAG_SHOW_UI : 0);
    getInstance(context).adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, flag);
}

From source file:com.xortech.sender.SmsReceiver.java

public void onReceive(final Context ctx, Intent intent) {
    // GET SMS MAP FROM INTENT
    Bundle extras = intent.getExtras();//from w  ww  . j a v a  2s  .c om
    context = ctx;

    // GPS INSTANCE
    gps = new GPSTracker(context);

    // LOAD PREFERENCES
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    secretCode = preferences.getString("secretCode", DEFAULT_CODE);
    tagID = preferences.getString("tagID", DEFAULT_TAGID);
    senderEnabled = preferences.getBoolean("senderEnabled", true);

    if (extras != null) {

        // GET THE RECEIVED SMS ARRAY
        Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);

        for (int i = 0; i < smsExtra.length; ++i) {

            // GET THE MESSAGE
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);

            // PARSE THE MESSAGE BODY
            String body = sms.getMessageBody().toString();
            String address = sms.getOriginatingAddress();
            long time = System.currentTimeMillis();

            // GET COORDINATES AND SEND A MESSAGE
            gps.getLocation();

            latitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLatitude()) / FIVE_DIGIT);
            longitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLongitude()) / FIVE_DIGIT);
            location = "Tag_ID:" + tagID + ":Location:" + latitude + "," + longitude;
            googleString = GOOGLE_STRING + latitude + "," + longitude + "(" + tagID + ")";

            if (body.equals(SECRET_LOCATION_A + secretCode)) {
                if (senderEnabled) {
                    if (latitude.equals("0.0") | longitude.equals("0.0")) {
                        SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null);
                    } else {
                        SmsManager.getDefault().sendTextMessage(address, null, googleString, null, null);
                    }
                }

                this.abortBroadcast();
            } else if (body.equals(SECRET_LOCATION_B + secretCode)) {
                if (senderEnabled) {
                    if (latitude.equals("0.0") | longitude.equals("0.0")) {
                        SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null);
                    } else {
                        SmsManager.getDefault().sendTextMessage(address, null, location, null, null);
                    }
                }

                this.abortBroadcast();
            } else if (body.contains("Tag_ID:")) {
                // ADD TO DATABASE
                MsgDatabaseHandler dbHandler = new MsgDatabaseHandler(context);

                // VERIFY IF THE TAG EXISTS IN THE ARRAY
                String addressExists = VerifyTagExist(address);

                String[] splitBody = body.split(":");
                String tag = splitBody[1];
                tag.trim();
                String coords = splitBody[3];
                String[] splitCoords = coords.split(",");
                String lat = splitCoords[0];
                lat.trim();
                String lon = splitCoords[1];
                lon.trim();
                String _time = String.valueOf(time);
                String toastMsg = null;

                // CHECK IF THE ADDRESS EXISTS FOR NAMING PURPOSES
                if (addressExists == null) {
                    dbHandler.Add_Message(new MessageData(tag, address, lat, lon, _time));
                    toastMsg = "Response Received: " + tag;
                } else {
                    dbHandler.Add_Message(new MessageData(addressExists, address, lat, lon, _time));
                    toastMsg = "Response Received: " + addressExists;
                }

                dbHandler.close();

                Toast.makeText(context, toastMsg, Toast.LENGTH_LONG).show();

                this.abortBroadcast();
            } else if (body.contains("Panic!")) {

                // OVERRIDE THE SILENT FEATURE
                AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
                audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                audio.setStreamVolume(AudioManager.STREAM_RING, max,
                        AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

                // DEFINE THE NOTIFICATION MANAGER
                notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);

                // START A TIMER
                mytimer = new Timer(true);

                // SOUND LOCATION ALARM
                soundUri = Uri.parse(BEGIN_PATH + context.getPackageName() + FILE_PATH);

                // DISPLAY TAG ID FOR EMERGENCY
                String[] splitBody = body.split("\n");
                String fieldTag = splitBody[1];
                String[] splitTag = fieldTag.split(":");

                emergencyTag = splitTag[1].trim();

                // TIMER FOR NOTIFICATIONS
                mytask = new TimerTask() {
                    public void run() {
                        // RUN NOTIFICATION ON TIMER
                        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                                .setSmallIcon(R.drawable.emergency).setContentTitle(PANIC_TXT)
                                .setContentText(emergencyTag + UNDER_DURRESS).setSound(soundUri); //This sets the sound to play

                        // DISPLAY THE NOTIFICATION
                        notificationManager.notify(0, mBuilder.build());
                    }
                };
                // START TIMER AFTER 5 SECONDS
                mytimer.schedule(mytask, FIVE_SECONDS);
            }
        }
    }

    // CLEAR THE CACHE ON RECEIVING A MESSAGE
    try {
        MyUpdateReceiver.trimCache(context);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.api.RequestHandler.java

/** 
 * The implementation of all the possible requests is here
 * -> "sounds": returns a list of available sounds on the phone
 * -> "screen": returns the screen state (whether the app. is on the foreground or not)
 * -> "play": plays a sound on the phone
 * -> "set": update Spydroid's configuration
 * -> "get": returns Spydroid's configuration (framerate, bitrate...)
 * -> "state": returns a JSON containing information about the state of the application
 * -> "battery": returns an approximation of the battery level on the phone
 * -> "buzz": makes the phone buuz // ww  w .  jav a 2  s .  co  m
 * -> "volume": sets or gets the volume 
 * @throws JSONException
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 **/
static private void exec(JSONObject object, StringBuilder response)
        throws JSONException, IllegalArgumentException, IllegalAccessException {

    SpydroidApplication application = SpydroidApplication.getInstance();
    Context context = application.getApplicationContext();

    String action = object.getString("action");

    // Returns a list of available sounds on the phone
    if (action.equals("sounds")) {
        Field[] raws = R.raw.class.getFields();
        response.append("[");
        for (int i = 0; i < raws.length - 1; i++) {
            response.append("\"" + raws[i].getName() + "\",");
        }
        response.append("\"" + raws[raws.length - 1].getName() + "\"]");
    }

    // Returns the screen state (whether the app. is on the foreground or not)
    else if (action.equals("screen")) {
        response.append(application.applicationForeground ? "\"1\"" : "\"0\"");
    }

    // Plays a sound on the phone
    else if (action.equals("play")) {
        Field[] raws = R.raw.class.getFields();
        for (int i = 0; i < raws.length; i++) {
            if (raws[i].getName().equals(object.getString("name"))) {
                mSoundPool.load(application, raws[i].getInt(null), 0);
            }
        }
        response.append("[]");
    }

    // Returns Spydroid's configuration (framerate, bitrate...)
    else if (action.equals("get")) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

        response.append("{\"streamAudio\":" + settings.getBoolean("stream_audio", false) + ",");
        response.append("\"audioEncoder\":\""
                + (application.audioEncoder == SessionBuilder.AUDIO_AMRNB ? "AMR-NB" : "AAC") + "\",");
        response.append("\"streamVideo\":" + settings.getBoolean("stream_video", true) + ",");
        response.append("\"videoEncoder\":\""
                + (application.videoEncoder == SessionBuilder.VIDEO_H263 ? "H.263" : "H.264") + "\",");
        response.append("\"videoResolution\":\"" + application.videoQuality.resX + "x"
                + application.videoQuality.resY + "\",");
        response.append("\"videoFramerate\":\"" + application.videoQuality.framerate + " fps\",");
        response.append("\"videoBitrate\":\"" + application.videoQuality.bitrate / 1000 + " kbps\"}");

    }

    // Update Spydroid's configuration
    else if (action.equals("set")) {
        final JSONObject settings = object.getJSONObject("settings");
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final Editor editor = prefs.edit();

        editor.putBoolean("stream_video", settings.getBoolean("stream_video"));
        application.videoQuality = VideoQuality.parseQuality(settings.getString("video_quality"));
        editor.putInt("video_resX", application.videoQuality.resX);
        editor.putInt("video_resY", application.videoQuality.resY);
        editor.putString("video_framerate", String.valueOf(application.videoQuality.framerate));
        editor.putString("video_bitrate", String.valueOf(application.videoQuality.bitrate / 1000));
        editor.putString("video_encoder", settings.getString("video_encoder").equals("H.263") ? "2" : "1");
        editor.putBoolean("stream_audio", settings.getBoolean("stream_audio"));
        editor.putString("audio_encoder", settings.getString("audio_encoder").equals("AMR-NB") ? "3" : "5");
        editor.commit();
        response.append("[]");

    }

    // Returns a JSON containing information about the state of the application
    else if (action.equals("state")) {

        Exception exception = application.lastCaughtException;

        response.append("{");

        if (exception != null) {

            // Used to display the message on the user interface
            String lastError = exception.getMessage();

            // Useful to display additional information to the user depending on the error
            StackTraceElement[] stack = exception.getStackTrace();
            StringBuilder builder = new StringBuilder(
                    exception.getClass().getName() + " : " + lastError + "||");
            for (int i = 0; i < stack.length; i++)
                builder.append("at " + stack[i].getClassName() + "." + stack[i].getMethodName() + " ("
                        + stack[i].getFileName() + ":" + stack[i].getLineNumber() + ")||");

            response.append("\"lastError\":\"" + (lastError != null ? lastError : "unknown error") + "\",");
            response.append("\"lastStackTrace\":\"" + builder.toString() + "\",");

        }

        response.append("\"activityPaused\":\"" + (application.applicationForeground ? "1" : "0") + "\"");
        response.append("}");

    }

    else if (action.equals("clear")) {
        application.lastCaughtException = null;
        response.append("[]");
    }

    // Returns an approximation of the battery level
    else if (action.equals("battery")) {
        response.append("\"" + application.batteryLevel + "\"");
    }

    // Makes the phone vibrates for 300ms
    else if (action.equals("buzz")) {
        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(300);
        response.append("[]");
    }

    // Sets or gets the system's volume
    else if (action.equals("volume")) {
        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (object.has("set")) {
            audio.setStreamVolume(AudioManager.STREAM_MUSIC, object.getInt("set"),
                    AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
            response.append("[]");
        } else {
            int max = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
            int current = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
            response.append("{\"max\":" + max + ",\"current\":" + current + "}");
        }
    }

}

From source file:org.protocoderrunner.base.BaseActivity.java

public void setVolume(int value) {
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int maxValue = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float val = (float) (value / 100.0 * maxValue);

    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, Math.round(val),
            AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}