How do I make a pop-up dialog box in Android with a lock screen and vibrate and ring like an alarm clock?

Source: Internet
Author: User


==================== Problem Description ====================
I want to apply pop-up dialog box, the program runs in the background, when the condition is reached after the dialog box and the vibration and ringing, but in the lock screen state but did not respond, what is the solution?
==================== Solution 1====================
Unlock Keyguardmanager manager = (Keyguardmanager) getsystemservice (Keyguard_service); Manager.inkeyguardrestrictedinputmode ()) {//In lock interface, interface is unlocked by Keyguardlock class method Keyguardlock Keyguard = Manager.newkeygu    Ardlock (Getlocalclassname ()); Keyguard.disablekeyguard ();}

Unlock requires permission:
<uses-permission android:name= "Android.permission.DISABLE_KEYGUARD"/>

Light the screen powermanager pm = (powermanager) getsystemservice (power_service); mwakelock = Pm.newwakelock ( Powermanager.acquire_causes_wakeup | Powermanager.screen_dim_wake_lock, "Simpletimer"); Mwakelock.acquire ();//.......mwakelock.release ();

To light the screen requires permission:
<uses-permission android:name= "Android.permission.WAKE_LOCK"/>
==================== Solution 2====================
According to LS method request Force open Lock, there will be press power key, the system will not enter sleep phenomenon

Refer to the following method to have the dialog box appear above the lock screen
The OnCreate method is used
Requestwindowfeature (Window.feature_no_title); Hide Title
Window win = GetWindow ();
Windowmanager.layoutparams winparams = Win.getattributes ();
Winparams.flags |= (WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Setrequestedorientation (0);

Use when Onresume
protected void Onresume () {
Super.onresume ();
Acquirewakelock ();
}

private void Acquirewakelock () {
if (Mwakelock = = null) {
LOG.I (TAG, "Activity begin Start");
PowerManager pm = (powermanager) getsystemservice (Context.power_service);
Mwakelock = Pm.newwakelock (Powermanager.screen_dim_wake_lock, This.getclass (). Getcanonicalname ());
Mwakelock.acquire ();
}

In OnPause
protected void OnPause () {
Super.onpause ();
......
Releasewakelock ();
}

private void Releasewakelock () {
if (Mwakelock! = null && Mwakelock.isheld ()) {
Mwakelock.release ();
Mwakelock = null;
}
Hope that the LZ has helped!

How do I make a pop-up dialog box in Android with a lock screen and vibrate and ring like an alarm clock?

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.