Java Code Examples for android.media.AudioManager#VIBRATE_SETTING_ON

The following examples show how to use android.media.AudioManager#VIBRATE_SETTING_ON . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
    // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
    // Phone app should separately check whether AudioManager#getRingerMode() returns
    // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
    int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
            AudioManager.VIBRATE_SETTING_OFF);
    boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);

    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");
        loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
    } finally {
        if (stmt != null) stmt.close();
    }
}
 
Example 2
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
    // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
    // Phone app should separately check whether AudioManager#getRingerMode() returns
    // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
    int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
            AudioManager.VIBRATE_SETTING_OFF);
    boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);

    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");
        loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
    } finally {
        if (stmt != null) stmt.close();
    }
}
 
Example 3
Source File: Ringer.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
public void updateRingerMode() {

		AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		synchronized (this) {
			int ringerMode = audioManager.getRingerMode();
			// Silent : stop everything
			if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
				stopRing();
				return;
			}

			// Vibrate
			int vibrateSetting = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
			// If not already started restart it
			if (vibratorThread == null && (vibrateSetting == AudioManager.VIBRATE_SETTING_ON || ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
				vibratorThread = new VibratorThread();
				vibratorThread.start();
			}

			// Vibrate only
			if (ringerMode == AudioManager.RINGER_MODE_VIBRATE || audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
				stopRinger();
				return;
			}

            //Ringer
			ringerWorker.startRinging(audioManager);
		}
	}
 
Example 4
Source File: Ringer.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Starts the ringtone and/or vibrator. 
 * 
 */
public void ring(String remoteContact, String defaultRingtone) {
    Log.d(THIS_FILE, "==> ring() called...");

    synchronized (this) {

    	AudioManager audioManager =
            (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    	
    	//Save ringtone at the begining in case we raise vol
        Ringtone ringtone = getRingtone(remoteContact, defaultRingtone);
        ringerWorker.setRingtone(ringtone);
        
    	//No ring no vibrate
        int ringerMode = audioManager.getRingerMode();
        if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
        	Log.d(THIS_FILE, "skipping ring and vibrate because profile is Silent");
        	return;
        }
        
        // Vibrate
        int vibrateSetting = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
        Log.d(THIS_FILE, "v=" + vibrateSetting + " rm=" + ringerMode);
        if (vibratorThread == null &&
        		(vibrateSetting == AudioManager.VIBRATE_SETTING_ON || 
        				ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
            vibratorThread = new VibratorThread();
            Log.d(THIS_FILE, "Starting vibrator...");
            vibratorThread.start();
        }

        // Vibrate only
        if (ringerMode == AudioManager.RINGER_MODE_VIBRATE ||
        		audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0 ) {
        	Log.d(THIS_FILE, "skipping ring because profile is Vibrate OR because volume is zero");
        	return;
        }

        // Ringer normal, audio set for ring, do it
        if(ringtone == null) {
        	Log.d(THIS_FILE, "No ringtone available - do not ring");
        	return;
        }

        ringerWorker.startRinging(audioManager);
    	
    }
}