android手机关机锁屏音

来源:互联网 发布:淘宝优惠款 编辑:程序博客网 时间:2024/04/26 01:39

android机器默认关机有锁屏音,播放这个声音的函数在KeyguardViewMediator.java  playSounds函数,只需要定义一个变量,接收到系统关机广播时,调用这个函数的时候直接返回就OK了。

 

private boolean mCanPlaySound = true; // add for bestone

private void playSounds(boolean locked) {
        // User feedback for keyguard.

        if (mSuppressNextLockSound) {
            mSuppressNextLockSound = false;
            return;
        }
       
        // start add for bestone
        if(!mCanPlaySound)
        {
          return;
        }
        // end add for bestone

        final ContentResolver cr = mContext.getContentResolver();
        if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1)
        {
            final String whichSound = locked
                ? Settings.System.LOCK_SOUND
                : Settings.System.UNLOCK_SOUND;
            final String soundPath = Settings.System.getString(cr, whichSound);
            if (soundPath != null) {
                final Uri soundUri = Uri.parse("file://" + soundPath);
                if (soundUri != null) {
                    final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
                    if (sfx != null) {
                        sfx.setStreamType(AudioManager.STREAM_SYSTEM);
                        sfx.play();
                    } else {
                        Xlog.d(TAG, "playSounds: failed to load ringtone from uri: " + soundUri);
                    }
                } else {
                    Xlog.d(TAG, "playSounds: could not parse Uri: " + soundPath);
                }
            } else {
                Xlog.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null");
            }
        }
    }     

 

 

private BroadcastReceiver mBroadCastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (action.equals(DELAYED_KEYGUARD_ACTION)) {

                int sequence = intent.getIntExtra("seq", 0);

                if (false) Xlog.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
                        + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);

                if (mDelayedShowingSequence == sequence) {
                    // Don't play lockscreen SFX if the screen went off due to
                    // timeout.
                    mSuppressNextLockSound = true;

                    doKeyguard();
                }
            } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
                mPhoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

                if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)  // call ending
                        && !mScreenOn                           // screen off
                        && mExternallyEnabled) {                // not disabled by any app

                    // note: this is a way to gracefully reenable the keyguard when the call
                    // ends and the screen is off without always reenabling the keyguard
                    // each time the screen turns off while in call (and having an occasional ugly
                    // flicker while turning back on the screen and disabling the keyguard again).
                    if (DEBUG) Xlog.d(TAG, "screen is off and call ended, let's make sure the "
                            + "keyguard is showing");
                    doKeyguard();
                }
            }
            // start add for bestone
            else if(action.equals(Intent.ACTION_SHUTDOWN))
            {
              mCanPlaySound = false;
            }
            // end add for bestone
            /*else if(action.equals(Intent.ACTION_SHUTDOWN)){
             Xlog.d("wgao","ACTION_SHUTDOWN ~~~"); 
             showDown_gotoSleep = true;
            }else if(action.equals(IPO_ENABLE)){
             Xlog.d("wgao","ACTION_SHUTDOWN_IPO ~~~");
             showDown_gotoSleep = true;
            }else if(action.equals(IPO_DISABLE)){
             Xlog.d("wgao","ACTION_BOOT_IPO ~~~");
             showDown_gotoSleep = false;
            }*/
        }
    };

 

原创粉丝点击