android 手机后台播音乐,设置闹钟,打一通电话,挂断电话后,闹钟与音乐同时响起
2014-11-05 17:08
816 查看
修改:
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;
}
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 5.0 播放音乐时闹钟响,此时来电话并挂断,闹钟和音乐同时响
- Android:手机做服务器控制多个手机客户端同时播放音乐(含源码)
- Android设置自定义手机铃声、短信、通知及闹钟铃声的方法
- Android 手机连接电脑调试同时允许手机访问SD卡的设置
- 后台播放音乐时,设置手机铃声,后台音乐不会暂停
- Android手机安全软件之设置电话拦截返回音浅析
- Android 同时设置多个闹钟
- 解决 后台播放音乐时,设置手机铃声,后台音乐不会暂停
- ym——Android从零开始(28)(来电铃声的设置、手机闹钟、手势识别)(新)
- Android手机安全软件之设置电话拦截返回音浅析
- 手机同时播放两个音乐 探讨二
- Android 手机应用开发经验 之电话与短信服务
- [JavaME]手机同时播放两个音乐 探讨一
- Android手机使用中国电信天翼上网设置
- 【andorid】同时设置android:gravity属性的值为两个
- 索爱将推Android系统Walkman音乐手机
- Android 手机GPRS 上网和彩信设置教程
- 手机同时播放两个音乐 探讨二[JavaME]
- 手把手教你给android手机设置WIFI无线网络
- android 闹钟程序源码(可多次响起,很实用)