2

I have an alarm scheduled. Using WakeLock.acquire() and KeyguardLock.disableKeyguard(), I am able to wake the screen up and show my activity. However, I'd prefer to just show a dialog. The built in alarm on my HTC and Samsung devices act this way. I expected to find a method on the KeyguardLock object, but I didn't see anything in the docs that led me in this direction. How can I keep the KeyguardLock on, but show my dialog on it the way the built-in alarms do. Here is my current code that runs in onCreate()

    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    keyguardLock = km.newKeyguardLock(KeyguardLockTag);
    keyguardLock.disableKeyguard();

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int flags = PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    wakeLock = pm.newWakeLock(flags, WakeLockTag);
    wakeLock.acquire();
Rich
  • 36,270
  • 31
  • 115
  • 154
  • have you found the solution? – Behzad Feb 22 '13 at 23:37
  • @Behzad I didn't end up doing it as described, but looking back now (this thread is over a year old), you can style your activity like a dialog to achieve the same result. If you're not familiar how to do this, Google "android style activity as dialog". It's easily done in the Activity element in the manifest. – Rich Feb 22 '13 at 23:51

1 Answers1

0

Just try this to wake your device screen even at lock.

package android.taskscheduler;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

public abstract class WakeIntentService extends IntentService
{
abstract void doReminderWork(Intent intent);
public static final String LOCK_NAME_STATIC = "your_package_name";
private static PowerManager.WakeLock lockStatic = null;

public static void acquireStaticLock(Context context){
   getLock(context).acquire();
}

synchronized private static PowerManager.WakeLock getLock(Context context)
{
   if(lockStatic == null)
       {
           PowerManager powManager = (PowerManager)     context.getSystemService(Context.POWER_SERVICE);

   lockStatic = powManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_STATIC);
   lockStatic.setReferenceCounted(true);
   }
   return (lockStatic);
}
public WakeIntentService(String name) 
{
   super(name);
}
@Override
        final protected void onHandleIntent(Intent intent)
{
       try{
            doReminderWork(intent);

        }finally
   {
       getLock(this).release();

       }
   }
}
Pattabi Raman
  • 5,814
  • 10
  • 39
  • 60