0

How to keep screen on in Android?

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + Uri.encode("+86 212312142")));
startActivityForResult(callIntent, 100);

I want the screen keep turn on, even in the phone dial activity. (No Dim)

I try this

PowerManager pm = (PowerManager) act.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "XXXX");
wakeLock.acquire();
Kara
  • 6,115
  • 16
  • 50
  • 57
Ah Lam
  • 167
  • 1
  • 2
  • 8

1 Answers1

0

I think you need to add extras permission to use wakelock

<uses-permission android:name="android.permission.WAKE_LOCK" />

but instead of wakelock I recommend you to use this :

@Override
    protected void onCreate(Bundle savedBundle) {
        super.onCreate(savedBundle);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

there is a good discussion about not using wakelock here -> Force Screen On

Community
  • 1
  • 1
Niko Adrianus Yuwono
  • 11,012
  • 8
  • 42
  • 64
  • This function is work perfectly in my activity . However, when i start Dial Activity (the Android default Dial Activity to have telephone call) , the screen will dim , and off at last. – Ah Lam May 23 '13 at 06:13
  • Have you tried the wake lock function?I guess it'll work but the downside is the device battery life will be significantly affected by the use of this API. Do not acquire PowerManager.WakeLocks unless you really need them, use the minimum levels possible, and be sure to release them as soon as possible. – Niko Adrianus Yuwono May 23 '13 at 07:27