English 中文(简体)
Anders: How to Toggle between Vibrate Cons (Always, Historical, only in Silent Mode, only when Not in Silent Mode)? 审校
原标题:Android: How to Toggle Between Vibrate Settings (Always, Never, Only in Silent Mode, Only When Not in Silent Mode)? Revisited

2. 寻找方法,在以下三者之间探讨:

  • Always
  • Never
  • Only in Silent Mode
  • Only When Not in Silent Mode

These choices are found by the path --- Menu >> Settings >> Sound >> Vibrate --- on the phone.

It is simple to change by navigation on the phone (by the way, my phone is a Motorola Atrix 2 with Android 2.3.3), but I have yet to come across methods to use in my code.

<><><>>>>

在被点击时,我基本上有应该操纵振动环境的县。 其中1个县是:

    bSilent.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
            audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

            Toast.makeText(getBaseContext(), "Set to Never", Toast.LENGTH_SHORT).show();
        }
    });

录音 管理人员的定义是:

final AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

安德森提供音频感乐器。 解决办法,但现在却被删除。 相反,他们提到“SerRingerMode”方法。

rel=“nofollow noreferer”>http://developer.android.com/vis/android/media/AudioManager.html

然而,利用这些职能(以及这些职能的任何组合)并不能有效地在四维系环境之间流动。 例如,如果我开始“走路”的话,我似乎不可能“走路”。 振动方法的所有组合只能从“途径”和“仅以温和方式”之间移动。 另一方面,如果我开始“无论谁”的话,所提供方法只能从“谁”和“仅仅在不温和的情况下”。

因此,恳请我保持沉默,希望它振动。 然后,我决定,我不想再 vi。 我无法从“途径”或“仅以温和方式”改为“无”。

<>Past Solutions and Posts

我知道,这在一定程度上是StackOverflow的一个重复员额。 这个问题在......之前已经提出。

Here: Vibrate settings on Android 2.2

https://stackoverflow.com/questions/11264550/changeing-vibrate-making>。 变化的制定

The former of the links provides an "answer". LuTHieR ends up in a discussion and eventually figures out a way on his own. He references the site:

https://android.goosourcegle.com/platform/ Packages/apps/Settings/+/froyo-release/src/com/android/制定/Soundetts.java

并且说,“我看一看 com子的源代码。 设置部分,并抄录了能够产生和避免的活力的方法”。

我仔细地看着这个网站,无法找到他所做的事情。 是否有任何人澄清他的解决办法?

<<><><><><>>>>><><><>>>>>

是否有办法精确地将“途径”、“谁”、“谁”与“谁不处于沉默模式”混为一谈?

问题回答

My solution (path of the function with income String sParam with needed mode of vibration set, refactoring if need to integer 0-3):

AudioManager audioManager = getSystemService( Context.AUDIO_SERVICE);

if( Build.VERSION.SDK_INT < 16)
{
    // sParam may be:
    // 0 - Always
    // 1 - Never
    // 2 - Only in silent mode (when sound is off)
    // 3 - Only when not in silent mode (when sound is on)

    if( (sParam.equals( "1") == true) || (sParam.equals( "3") == true))
    {
        Settings.System.putInt( Static.contextApplication.getContentResolver(), "vibrate_in_silent", 0);
        if( sParam.equals( "1") == true) 
            audioManager.setVibrateSetting( AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

        if( sParam.equals( "3") == true)  
            audioManager.setVibrateSetting( AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
    }

    if( (sParam.equals( "0") == true) || (sParam.equals( "2") == true))
    {
        Settings.System.putInt( Static.contextApplication.getContentResolver(), "vibrate_in_silent", 1);
        if( sParam.equals( "0") == true)  
            audioManager.setVibrateSetting( AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
        if( sParam.equals( "2") == true)  
            audioManager.setVibrateSetting( AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
    }
}
// else (for new SDK > 16 via setRingerMode() ??? )




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签