android 手机后台播音乐,设置闹钟,打一通电话,挂断电话后,闹钟与音乐同时响起

编程入门 行业动态 更新时间:2024-10-24 11:18:03

android 手机后台播音乐,设置<a href=https://www.elefans.com/category/jswz/34/1749712.html style=闹钟,打一通电话,挂断电话后,闹钟与音乐同时响起"/>

android 手机后台播音乐,设置闹钟,打一通电话,挂断电话后,闹钟与音乐同时响起

修改:

frameworks\base\media\java\android\media\MediaFocusControl.java:

1、import packages:

import com.android.internal.telephony.ITelephony;

import android.os.ServiceManager;

 

2、增加获取当前Phone Call State的方法getPhoneCallState():

    private int getPhoneCallState(){

       int phoneCallState = TelephonyManager.CALL_STATE_IDLE;

 

       TelephonyManager telephonyManager = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);

       ITelephony telephonyService = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));

 

       if (telephonyService != null) {

           Log.w(TAG, "getPhoneCallState: mTelephonyService != null");

            try {

                phoneCallState = telephonyService.getPreciseCallState();

              Log.w(TAG, "getPhoneCallState: telephonyService.getPreciseCallState() = " + phoneCallState);

            } catch (RemoteException ex) {

              if(telephonyManager != null){

                    phoneCallState = telephonyManager.getCallState();

                  Log.w(TAG, "getPhoneCallState: telephonyManager.getCallState() = " + phoneCallState);

              }

                Log.w(TAG, "Catch exception when getPreciseCallState: ex = "

                        + ex.getMessage());

            }

        } else {

           Log.w(TAG, "getPhoneCallState: telephonyService == null");

           if(telephonyManager != null){

                phoneCallState = telephonyManager.getCallState();

              Log.w(TAG, "getPhoneCallState: telephonyManager.getCallState() = " + phoneCallState);

           }

        }

        Log.w(TAG, "getPhoneCallState: phoneCallState = " + phoneCallState);

       return phoneCallState;

    }

 

3、修改

    private boolean canReassignAudioFocus() {

        // focus requests are rejected during a phone call or when the phone is ringing

        // this is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus

        if (!mFocusStack.isEmpty() && mFocusStack.peek().hasSameClient(IN_VOICE_COMM_FOCUS_ID)) {

            return false;

        }

        return true;

    }

    private boolean canReassignAudioFocus() {

        // focus requests are rejected during a phone call or when the phone is ringing

        // this is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus        

        if (!mFocusStack.isEmpty() && mFocusStack.peek().hasSameClient(IN_VOICE_COMM_FOCUS_ID) && (getPhoneCallState() != TelephonyManager.CALL_STATE_IDLE)) {

           Log.w(TAG, "canReassignAudioFocus: return false");

            return false;

        }

       Log.w(TAG, "canReassignAudioFocus: return true");

        return true;

    }

更多推荐

android 手机后台播音乐,设置闹钟,打一通电话,挂断电话后,闹钟与音乐同时响起

本文发布于:2024-03-09 02:30:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1723425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:闹钟   音乐   后台   电话   手机

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!