Solved

How to turn on screen programmatically in Android?

Posted on 2014-09-26
1
1,780 Views
Last Modified: 2014-10-31
I have developed an App that loads automatically when smartphone receives an SMS message.

Problem is that when screen's phone is off or in "black" mode, App doesn't load when SMS arrives. I need that my app turns screen on programmatically. Is that possible? I found several past solutions but no one has worked.

I tried:
WindowManager.LayoutParams params =
                getWindow().getAttributes();
                params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
                params.screenBrightness = 0;
                getWindow().setAttributes(params);

Open in new window

And tried:
super.onCreate(savedInstanceState);
setContentView(R.layout.my_main_activity);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Open in new window

And no success.

I've been advised that this code could do the trick:

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Open in new window


However, Android Studio shows me error:
Cannot resolve symbol 'FLAG_SHOW_WHEN_LOCKED'

Open in new window



Is there any import or setting that I should do?
0
Comment
Question by:miyahira
1 Comment
 
LVL 16

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 40354439
It looks like that FLAG_SHOW_WHEN_LOCKED has been set to not work with password locked devices.

https://code.google.com/p/android-developer-preview/issues/detail?id=1150
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
onenote 2016 sync 40 211
messenger app crashes 7 49
Xamarin 10 44
RTSP blocked by AT&T? 11 28
This is an explanation of a simple data model to help parse a JSON feed
For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now