当前位置: 首页>>代码示例>>Java>>正文


Java AudioManager.RINGER_MODE_VIBRATE属性代码示例

本文整理汇总了Java中android.media.AudioManager.RINGER_MODE_VIBRATE属性的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.RINGER_MODE_VIBRATE属性的具体用法?Java AudioManager.RINGER_MODE_VIBRATE怎么用?Java AudioManager.RINGER_MODE_VIBRATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.media.AudioManager的用法示例。


在下文中一共展示了AudioManager.RINGER_MODE_VIBRATE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String event = null;
    String type = null;

    switch(intent.getAction()){
        case Intent.ACTION_SCREEN_OFF:
            event = DeviceEvent.EVENT_SCREEN_OFF;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_SCREEN_ON:
            event = DeviceEvent.EVENT_SCREEN_ON;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_USER_PRESENT:
            event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_BOOT_COMPLETED:
            event = DeviceEvent.EVENT_BOOT_COMPLETED;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_SHUTDOWN:
            event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_BATTERY_LOW:
            event = DeviceEvent.EVENT_BATTERY_LOW;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_BATTERY_OKAY:
            event = DeviceEvent.EVENT_BATTERY_OKAY;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_CONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_DISCONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case AudioManager.RINGER_MODE_CHANGED_ACTION:
            AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
            switch (am.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    event = DeviceEvent.EVENT_RINGER_SILENT;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_VIBRATE:
                    event = DeviceEvent.EVENT_RINGER_VIBRATE;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_NORMAL:
                    event = DeviceEvent.EVENT_RINGER_NORMAL;
                    type = DeviceEvent.TYPE_RINGER;
                    break;
            }
        default:
            break;
    }

    if (type != null)
        output(new DeviceEvent(type, event));
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:76,代码来源:DeviceEventUpdatesProvider.java

示例2: shouldVibrateNew

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean shouldVibrateNew(Context context, int ringerMode) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

    if (vibrator == null || !vibrator.hasVibrator()) {
        return false;
    }

    boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;

    if (vibrateWhenRinging) {
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
    } else {
        return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
    }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:16,代码来源:IncomingRinger.java

示例3: giveFeedback

/**
 * Tone play to be used when a button in dialpad
 * is pressed
 * @param tone The tone associated to the button
 */
public void giveFeedback(int tone) {
	
	switch (ringerMode) {
		case AudioManager.RINGER_MODE_NORMAL:
			if (dialPressVibrate) {
			    vibrator.vibrate(HAPTIC_LENGTH_MS);
			}
			if (dialPressTone) {
			    ThreadedTonePlay threadedTone = new ThreadedTonePlay(tone);
			    threadedTone.start();
			}
			break;
		case AudioManager.RINGER_MODE_VIBRATE:
			if (dialPressVibrate) {
			    vibrator.vibrate(HAPTIC_LENGTH_MS);
			}
			break;
		case AudioManager.RINGER_MODE_SILENT:
			break;
	}
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:26,代码来源:DialingFeedback.java

示例4: onIncomingCallRinging

public void onIncomingCallRinging() {
    int ringerMode = NotificationUtil.getRingerMode(this);
    if (ringerMode != AudioManager.RINGER_MODE_SILENT) {
        if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
            mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
            mVibrator.vibrate(new long[]{500, 1000}, 0);
        } else {
            Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            mMediaPlayer = new MediaPlayer();
            try {
                mMediaPlayer.setDataSource(this, uri);
                mMediaPlayer.setLooping(true);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:20,代码来源:BaseCallActivity.java

示例5: validateState

private void validateState(AudioManager manager) {

		int ringer = manager.getRingerMode();
		
		if (ringer != AudioManager.RINGER_MODE_SILENT 
				&& ringer != AudioManager.RINGER_MODE_VIBRATE) {
			
			// if volume is zero set it to medium
			int volume = manager.getStreamVolume(AudioManager.STREAM_RING);
			if (volume == 0) {
				manager.setStreamVolume(AudioManager.STREAM_RING, 4, 0);
				manager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 4, 0);
			}
		}
		
		// send internal volume changed notification
		mActivity.sendBroadcast(new Intent(Constants.ACTION_VOLUME_UPDATED));
	}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:18,代码来源:RingerSettingHandler.java

示例6: onIncomingCallRinging

public void onIncomingCallRinging() {
    int ringerMode = NotificationUtil.getRingerMode(this);
    if(ringerMode != AudioManager.RINGER_MODE_SILENT){
        if(ringerMode == AudioManager.RINGER_MODE_VIBRATE){
            mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
            mVibrator.vibrate(new long[] {500, 1000}, 0);
        } else {
            Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            mMediaPlayer = new MediaPlayer();
            try {
                mMediaPlayer.setDataSource(this, uri);
                mMediaPlayer.setLooping(true);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:20,代码来源:BaseCallActivity.java

示例7: shouldVibrateNew

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean shouldVibrateNew(Context context, int ringerMode) {
  Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

  if (vibrator == null || !vibrator.hasVibrator()) {
    return false;
  }

  boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;

  if (vibrateWhenRinging) {
    return ringerMode != AudioManager.RINGER_MODE_SILENT;
  } else {
    return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:16,代码来源:IncomingRinger.java

示例8: isMuted

/**
 * Checks if device is muted.
 */
static String isMuted(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch( audio.getRingerMode() ){
        case AudioManager.RINGER_MODE_SILENT:
            return "true";
        case AudioManager.RINGER_MODE_VIBRATE:
            return "true";
        default:
            return "false";
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:CrashDetails.java

示例9: updateRingerMode

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);
		}
	}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:29,代码来源:Ringer.java

示例10: onItemClick

public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
	
	AudioManager manager = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE);
	if (manager != null) {

		int ringerMode = AudioManager.RINGER_MODE_NORMAL;
		int vibroMode = AudioManager.VIBRATE_SETTING_ON;
		
		switch(index) {
			case 0: // silent
				ringerMode = AudioManager.RINGER_MODE_SILENT;
				vibroMode = AudioManager.VIBRATE_SETTING_ONLY_SILENT;
				break;
			case 1: // vibro
				ringerMode = AudioManager.RINGER_MODE_VIBRATE;
				vibroMode = AudioManager.VIBRATE_SETTING_ON;
				break;
			case 2: // sound
				ringerMode = AudioManager.RINGER_MODE_NORMAL;
				vibroMode = AudioManager.VIBRATE_SETTING_OFF;
				break;
			case 3: // sound and vibro
				ringerMode = AudioManager.RINGER_MODE_NORMAL;
				vibroMode = AudioManager.VIBRATE_SETTING_ON;
				break;
		}
		
		// update manager modes
		
		// update
		manager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, vibroMode);
		manager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, vibroMode);
		manager.setRingerMode(ringerMode);
		
		validateState(manager);
	}
	
	mDialog.hide();
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:39,代码来源:RingerSettingHandler.java

示例11: initAudioManager

private void initAudioManager() {
    mAudioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

    int mode = mAudioManager.getRingerMode();
    if (mode == AudioManager.RINGER_MODE_VIBRATE
            || mode == AudioManager.RINGER_MODE_SILENT) {
        // Normal mode will be audible and may vibrate according to user settings.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            NotificationManager n  = (NotificationManager) mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
            boolean isPolicyGranted = n != null && n.isNotificationPolicyAccessGranted();
            // fixme 7.0手机 如果没有这个权限 直接调用setRingerMode会报出 Not allowed to change Do Not Disturb state的异常.
            if (isPolicyGranted) {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    }
    mAudioMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int audioCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (mAudioMaxVolume != 0) {
        mCurrentVolume = (int) (((float) audioCurrentVolume / (float) mAudioMaxVolume) * 100);
    }
    PlayerLog.d(TAG, "initAudioManager mCurrentVolume is " + mCurrentVolume +
            " , mAudioMaxVolume is " + mAudioMaxVolume +
            " , audioCurrentVolume is " + audioCurrentVolume);
}
 
开发者ID:xinpianchang,项目名称:NSMPlayer-Android,代码行数:27,代码来源:VMoviePlayer.java

示例12: hideVibrateIcon

private void hideVibrateIcon() {
    if (mSbService == null || mContext == null) return;
    try {
        AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
            XposedHelpers.callMethod(mSbService, "setIconVisibility", "volume", false);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:11,代码来源:SystemIconController.java

示例13: findCurrentState

private void findCurrentState() {
    ContentResolver cr = mContext.getContentResolver();
    boolean vibrateWhenRinging = Settings.System.getInt(cr, SETTING_VIBRATE_WHEN_RINGING, 0) == 1;
    int zenMode = Settings.Global.getInt(cr, SETTING_ZEN_MODE, ZEN_MODE_OFF);
    int ringerMode = mAudioManager.getRingerMode();

    mRingerIndex = 0;

    for (int i = 0; i < RINGERS.length; i++) {
        Ringer r = RINGERS[i];
        if ((ringerMode == r.mRingerMode) && (ringerMode == AudioManager.RINGER_MODE_SILENT) &&
                (zenMode == r.mZenMode)) {
            mRingerIndex = i;
            break;
        }
        if ((ringerMode == r.mRingerMode) && (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
            mRingerIndex = i;
            break;
        }
        if ((ringerMode == r.mRingerMode) && (ringerMode == AudioManager.RINGER_MODE_NORMAL) &&
                (r.mVibrateWhenRinging == vibrateWhenRinging)) {
            mRingerIndex = i;
            break;
        }
    }
    if (DEBUG) log(getKey() + ": Current ringerIndex=" + mRingerIndex + ", ringerMode=" + ringerMode);
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:27,代码来源:RingerModeTile.java

示例14: playRingtone

public void playRingtone() {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

    // Honour silent mode
    switch (audioManager.getRingerMode()) {
        case AudioManager.RINGER_MODE_NORMAL:
            mPlayer = new MediaPlayer();
            mPlayer.setAudioStreamType(AudioManager.STREAM_RING);

            try {
                if(hasSIM())
                    mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
                else
                    mPlayer.setDataSource(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
                mPlayer.prepare();
            } catch (IOException e) {
                Log.e(LOG_TAG, "Could not setup media player for ringtone");
                mPlayer = null;
                return;
            }
            mPlayer.setLooping(true);
            mPlayer.start();
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
            if(mVibrator.hasVibrator()) {
                long[] pattern = {0, 500, 200};

                // The '0' here means to repeat indefinitely
                // '0' is actually the index at which the pattern keeps repeating from (the start)
                // To repeat the pattern from any other point, you could increase the index, e.g. '1'
                mVibrator.vibrate(pattern, 0);
            }
            break;
    }
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:36,代码来源:AudioPlayer.java

示例15: volumeProfileEnabled

/**
 * Check if the device can currently output sound, by checking the media profile. This is unfortunately
 * not foolproof, due to the various ways different ROM and device manufacturers link the stream types.
 *
 * @param audioManager object
 * @return true if the device will output sounds, false otherwise
 */
private static boolean volumeProfileEnabled(@NonNull final AudioManager audioManager) {

    switch (audioManager.getRingerMode()) {

        case AudioManager.RINGER_MODE_NORMAL:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_NORMAL");
            }
            return true;
        case AudioManager.RINGER_MODE_VIBRATE:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_VIBRATE");
            }
            break;
        case AudioManager.RINGER_MODE_SILENT:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_SILENT");
            }
            break;
        default:
            if (DEBUG) {
                MyLog.w(CLS_NAME, "volumeProfileEnabled: Default");
            }
            break;
    }

    return false;

}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:36,代码来源:VolumeHelper.java


注:本文中的android.media.AudioManager.RINGER_MODE_VIBRATE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。