【Android】系統音量及螢幕亮度調節

來源:互聯網
上載者:User

標籤:

螢幕亮度調節
/** * 滑動改變亮度,不需要許可權 * * @param percent 亮度百分比,值為0.0----1.0 */private void onBrightnessSlide(float percent) {    if (mBrightness < 0) { // mBrightness是當前螢幕的亮度        mBrightness = getWindow().getAttributes().screenBrightness;        if (mBrightness <= 0.00f)            mBrightness = 0.50f;        if (mBrightness < 0.01f)            mBrightness = 0.01f;        // 顯示        mOperationBg.setImageResource(R.drawable.video_brightness_bg);        mVolumeBrightnessLayout.setVisibility(View.VISIBLE);    }    WindowManager.LayoutParams lpa = getWindow().getAttributes();    lpa.screenBrightness = mBrightness + percent;    if (lpa.screenBrightness > 1.0f)        lpa.screenBrightness = 1.0f;    else if (lpa.screenBrightness < 0.01f)        lpa.screenBrightness = 0.01f;    getWindow().setAttributes(lpa);    ViewGroup.LayoutParams lp = mOperationPercent.getLayoutParams();    //這部分是改變圖片上面的當前亮度的進度的    lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);    mOperationPercent.setLayoutParams(lp);}
音量大小
/** * 音量大小,不需要許可權 */public class MainActivity extends Activity {    private static final String TAG = "MainActivity";    private AudioManager mAudioManager;    private int currentVolume;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);        // 最大音量        int maxVolume = mAudioManager                .getStreamMaxVolume(AudioManager.STREAM_MUSIC);        Log.i(TAG, "最大音量:" + maxVolume);        currentVolume = mAudioManager                .getStreamVolume(AudioManager.STREAM_MUSIC);        Log.i(TAG, "當前音量:" + currentVolume);    }    public void up(View view) {        // 音量增大        // AudioManager.STREAM_SYSTEM        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,                AudioManager.ADJUST_RAISE, AudioManager.FX_FOCUS_NAVIGATION_UP);        currentVolume = mAudioManager                .getStreamVolume(AudioManager.STREAM_MUSIC);        Log.i(TAG, "當前音量:" + currentVolume);    }    public void down(View view) {        // 音量減小        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,                AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP);        currentVolume = mAudioManager                .getStreamVolume(AudioManager.STREAM_MUSIC);        Log.i(TAG, "當前音量:" + currentVolume);    }}

歡迎androider掃描以下二維碼關注公眾號:愛安卓 ,或者搜尋 : loveandroid321關注

【Android】系統音量及螢幕亮度調節

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.