Android TV - Prevent Screen Saver From Appearing - android

I am creating a standard Android TV app which plays some videos and ran into an issue where screen saver turns on while I'm watching a video.
How can I prevent that from happening? Is there any trigger which I can trigger when I want for a screen to be ON all the time and prevent screen saver from appearing?
This looks like a good solution but screen saver still appears:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); works on any device when it is set at the beginning of your activity. Where is that code being set? Is it in your main activity or also in your video playback activity?
You can take a look at the Keeping the Device Awake guide for more information.

If you are using a SurfaceView to display your video, you should call .setKeepScreenOn(true); method of the SurfaceView instance.

Related

Video Freeze after lock screen on SurfaceView using SurfaceView and MediaPlayer

I was trying to use SurfaceView and MediaPlayer to Display video on Android.
I got a bug now that if I press the power button to lock the screen and then unlock it, The Video displayed on the MediaPlayer is gone and there is only sound. Normally for this situation the surfaceView would be somehow freeze to the last frame of the video before I lock the phone.
It works fine when I hide the screen(such as go to home and open another application) But it just does not work when I lock the phone. I think they both pass the onPause and onResume so I do not understand why would there be different logic.
I'd like to know if there is a solution to solve my problem.
Thanks!
I'm not sure exactly what's going on, but there's a general class of problem that is likely the cause of your trouble.
If your lockscreen is orientation-independent, or wants to be oriented the same way the device is, then the Activity won't be restarted to change orientation. In this case, turning the display off and back on with the power button won't cause the SurfaceView's surface to be destroyed. So if your app is relying on the surfaceCreated and surfaceChanged callbacks to fire to make things happen, then things won't happen.
If you leave the Activity and come back, the Surface does get destroyed and re-created.
The relationship between the Activity lifecycle and the Surface lifecycle is a bit complicated; you can find some notes about it in this article, including two basic patterns for structuring an app. Examples of both "styles" of SurfaceView management can be found in Grafika.
I can't make specific recommendations without knowing how your app works, but mainly you just need to look at what your app does with the idea that Activity and Surface lifetimes are not tightly coupled.
OK, I fix this in a weird way, I think it is probably a bug of Android. Don't have time to do enough testing on this.
First surely as #fadden says you need to have a mMediaPlayer.setDisplay(myHolder) elsewhere not in the surfaceChanged or surfaceCreated since they may not be called while resume from locked screen.
For me the problem still persist after I changed it this way. Here is what I changed that solved the problem: Instead of mMediaPlayer = new MediaPlayer(), we should use mMediaPlayer = MediaPlayer.create(MediaActivity.this, fileUri)

Android lock screen / media controls on the lock screen

i have a few questions, to which i haven't found answers till now, despite searching the forum and much of googling.
On thing first, i'm developing for android gingerbread, so newer/not all functions are available.
Is it somehow possible to force the lock screen to redraw/update?
Can i somehow manipulate the built-in media controls on the lock screen, which appear when i'm playing music, through a function/an intent or something? For example that the media controls show the pause state (only the play button is shown) instead of showing the play state (3 buttons are shown). Because i'm developing for gingerbread, i cannot use the RemoteControlClient.
Can i somehow dynamically disable/unregister the appearance of the media controls on the lock screen through code? The media controls on the lock screen shall not be shown despite playing music.
EDIT
Upon the answer of CommonsWare, for the second and third question, i use a cyanogen mod rom, so the media controls are comming from cyanogen.
Is it somehow possible to force the lock screen to redraw/update?
Not really.
Can i somehow manipulate the built-in media controls on the lock screen
Can i somehow dynamically disable/unregister the appearance of the media controls on the lock screen through code?
There are no "built-in media controls on the lock screen" in Android 2.3. Certain devices from certain device manufacturers may have extended their lockscreens support media controls, in which case you would have to ask your questions of those device manufacturers.

Android: Recognising Gestures when screen is locked

I am currently in the process of creating an MP3 player. In particular, the main mode of user input is in the form of (touchscreen) gestural input. I would like to add the functionality allowing users to continue interacting with the MP3 player when the screen is locked. That is, how can I get the device (A Galaxy S3 in particular if it's worth mentioning) to recognise gestures in the lock screen and "parse" them to the MP3 player?
Note: by "locked" I mean when one can see the lock screen (i.e. not when the screen is turned off).
How would I go about doing this?
Thanks in advance.
The recommended way is to make Lock Screen Widgets. These are widgets that allow you to interact with apps in the lockscreen such as the Google Play Music app.
Check out the official tutorial here:
http://developer.android.com/guide/topics/appwidgets/index.html#lockscreen

Is it possible to process the video (preview) stream without displaying it on the screen in android?

I have doing a basic object detection on the camera preview screen in Android (greater than 3.2). For the devices which do not support processing on preview screen, I am buffering the preview screen, processing it and clearing the buffer. This part is working as desired.
What I now want is this app to run in the background while any other app is running in the foreground. I am using android service and am able to run a small test app in the background. However my concern is with the camera preview app.
I don't want to display the preview screen but use the preview screen information for processing. This might be too much to ask, but I wanted to know if this is even possible. I came across this link which shows some hope. Basically I want to process the video (preview) stream without displaying it on the screen. If this is doable, then I can think of putting this app in the background and some other app in the foreground.
Unfortunately I won't be able to share the code, however it is the standard logic of creating a surface view and starting the preview.
I would really appreciate any insight into this.
Check comments here.Basically he opens camera hardware, set preview callback and do startpreview without setting the previewDisplay (this might not work on every device). You can try this from your background service. All this will work if your foreground doesn't access the camera app. Please update this if it works. I am interested to know.

Is It possible to set Image as ScreenSaver in Android?

I want to know that Is It possible in Android to set an Image as screenSaver.. I am not sure about the feasibily of screen saver...That is when the phone is Idle, then Instead of showing the black blank screen, my application check the Idle time using OnUserInteraction() method and set an Image as screen saver...?? Please let me know If anybody know about this..
onUserInteraction() is deprecated for a start, and it only listens for events on your Activity.
Secondly, having such a screensaver would require that you use WakeLocks, which consume extra battery. And for a screensaver type app, the battery usage would be extremely high.
You might want to look into Daydreams now, assuming you're fine with Android 4.2 and above only.

Categories

Resources