Android source code: instant screen notification after the screen lock and off calls are connected. During the call, the other party fails to display the screen.

Source: Internet
Author: User

In actual development of the Android source code, two problems are encountered: instant screen notification after the screen is disconnected from the screen lock, and instant screen notification during the call; because the problem of wake-up on the screen is used in many places, I don't want to modify the source code, so I am afraid that it will lead to more problems.
To solve these two problems, we should adopt a direct solution, that is, the screen will be lit immediately after the screen is disconnected and then released in a few seconds. If: when the recipient hangs up and does not display the screen during the call, the user clicks the screen and releases the screen a few seconds later;
This method of bright screen can be placed in the Call_STATE_IDLE and Call_State_OFFHooK statuses of the Phone Monitor for processing.
In these two states, we will encounter a problem: the release of a lock is clearly implemented, but the screen is still dark. No black screen, no standby. In fact, no bright screen locks are released when the problem persists. If Call_STATE_IDLE and Call_State_OFFHooK are locked multiple times, the locks generated each time are different, even if the same lock name is used, however, the lock is not released and will not be pushed to the screen. Therefore, in Call_STATE_IDLE and Call_State_OFFHooK, you must specify that the new lock is only performed once and release the corresponding lock. In this way, after the screen is highlighted, the screen is displayed after several seconds (the time is controlled by message.
The Code is as follows:
[Java]
TelephonyManager mTelephonyMgr = (TelephonyManager) this
. GetSystemService (Context. TELEPHONY_SERVICE );

MTelephonyMgr. listen (new TeleListener (),
PhoneStateListener. LISTEN_CALL_STATE );
// ====================================
 
// Add by kylin 2011.11.22 begin

Handler myHandler = new Handler (){
@ Override
Public void handleMessage (Message msg ){
// TODO Auto-generated method stub
Super. handleMessage (msg );
If (null! = Wl ){
Wl. release ();
}
}

};

Handler myHandler2 = new Handler (){
@ Override
Public void handleMessage (Message msg2 ){
// TODO Auto-generated method stub
Super. handleMessage (msg2 );
If (null! = Wl2 ){
Wl2.release ();
}
}

};

// End
 
// ================================================ ============
 
Class TeleListener extends PhoneStateListener {
 
@ Override
Public void onCallStateChanged (int state, String incomingNumber ){
Super. onCallStateChanged (state, incomingNumber );
Switch (state ){
Case TelephonyManager. CALL_STATE_IDLE :{
// Add by kylin 2011.10.21

String getElapsedTimeTemp = mCallCard. getElapsedTime (). toString ();


If (getElapsedTimeTemp! = Null &&! GetElapsedTimeTemp. trim (). equals ("") & PhoneApp. getInstance (). isVTCall () = false ){
// If (PhoneApp. getInstance (). isVTCall () = false ){
GetToast ();
}

Pm. setBtnBacklight (false );

MFlag = false;

MFlag2 = false;

 
// End
Break;
}
 
Case TelephonyManager. CALL_STATE_OFFHOOK :{
MFlag = true;
Pm. setBtnBacklight (true );

If (! MFlag2 ){
Pm2 = (PowerManager) getSystemService (Context. POWER_SERVICE );
Wl2 = pm2.newWakeLock (PowerManager. ACQUIRE_CAUSES_WAKEUP | PowerManager. SCREEN_DIM_WAKE_LOCK, "InCallScreen ");
// Wl2.setReferenceCounted (false );
Wl2.acquire ();
 
Message msg2 = new Message ();
Msg2.what = 200;
MyHandler2.sendMessageDelayed (Ms 2, 5000 );
MFlag2 = true;
}

Break;
}
 
Case TelephonyManager. CALL_STATE_RINGING :{
Pm. setBtnBacklight (true );
Break;
}
Default:
Break;
}
}
 
}
// ==========================================
 
Private void getToast (){

If (mFlag = true ){
Pm = (PowerManager) getSystemService (Context. POWER_SERVICE );
Wl = pm. newWakeLock (PowerManager. ACQUIRE_CAUSES_WAKEUP | PowerManager. SCREEN_DIM_WAKE_LOCK, "InCallScreen ");
Wl. acquire ();

MFlag = false;

Message msg = new Message ();
Msg. what = 100;
MyHandler. sendMessageDelayed (msg, 2000 );

// Wl. release ();
}
}


From Kylin Qilin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.