I have an android application that will dim the screen due to inactivity. This is typically after 15 seconds. Any touch brings the screen to full brightness.
When the screen dims I want to perform some actions on screen.
It seems there is no intent to capture screen dim.
My plan is to create a service that runs in the background. This service will find the dim due to inactivity timeout (15s) and start a runnable. Once the runnable executes it will perform my actions screen.
The service will also need to detect any touch from any screen to immediately go back.
Is there a simpler way to do this? Think of my screen action as turning on a screen saver. A screen saver that must be active only when the screen has dimmed due to inactivity.
It looks like I could have used the PowerManager in Android to check if the device is in idle mode. However my version of Android is so old this has not been implemented.
Related
Is it possible to stop GIF animation and after some time start animation again? Let me explain you what exactly i am trying to do.
I want to set GIF file as wallpaper and 2 mins i want to stop the GIF animation. AND when i press the power button and unlock the device than again my GIF animation start and after 2 min it will stop.IS THIS THING IS POSSIBLE?
And what i have already DONE is i can set GIF file as wallpaper. but i cant find any way to stop that animation.So what i do is set another image as wallpaper but when i unlock the screen it will not set GIF wallpaper again and its only show old png image.
There is an app called ITTT (If this, then that). It allows you to set actions that are triggered by certain things. For example, to get the result you're looking for, you would set the action, change wallpaper to (image), with the trigger being "locking phone", and another action, change wallpaper to (GIF), wit the trigger being "unlocking phone).
The resulting effect would be that your wallpaper automatically switches between GIF and PNG when you lock/unlock your phone.
I'm trying to find out what the difference is in the activity lifecycle when a lock-screen is enabled versus disabled.
Scenario A (no lock-screen)
App is running
power button is hit to turn display off
power button is hit to turn display on
App is immediately resumed
Scenario B (lock screen enabled, swipe to unlock)
App is running
power button is hit to turn display off
power button is hit to turn display on
Swipe screen to unlock
App is resumed (but we are getting a bug in the display, which is where we are trying to find the difference)
I have printed out the activity lifecycle for both scenarios and they show up identical for both scenarios.
What might be the difference in the lifecycle that would cause this different behavior when using lock-screen versus no lock-screen?
Take a look at this documentation. It could be that the lock screen would imply that the app process is killed and therefore data is lost (which is necessary to present the page and therefore the app crashes). I would suggest to debug the activity states to find the answer you're looking for.
You can test it with writing Logs into onResume(), onCreate(), onPause(), onDestroy() etc.
Also pressing Power button and and opening LockScreen changes the devices screen orientation into "Portrait" mode(Phones and tablets with locked rotation only). It may cause different reactions you are mentioned about.
Im working on a 3D live wallpaper for android using rajawali. When I turn the screen off and on, its loading the whole scene again what takes some seconds depending on device and scene complexity. Id like to keep my wallpaper in memory "forever" to have the wallpaper visible instantly after the screen turn on.
From what I have found this behavior is because openGL loose context when calling OnPause and OnResume events. I tried setPreserveEglContextOnPause which "may" preserve context, but actually it changes nothing.
Can anybody help me to solve this problem?
I created an android app. The screen never turns off:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Now I want to show a picture if the screen is not pressed for 5 minutes or something else. The app should not be closed, when pressing on the image the app should be open.
How can I realize that?
I would discourage you from taking this approach. Users expect to have a consistent user experience between various apps on their devices, and likely have a preference to how their device sleeps, either by having specified a sleep timeout or displaying a daydream as introduced in Android 4.2.
If you'd like to provide users with the option to display a screensaver associated with your app, I suggest including a Daydream in your app and otherwise acknowledging the user's preferences.
That being said, if you cannot use Daydream, you could observe if the app is being used or not. Two things come to mind:
Have the root view of your activity intercept touch events to observe if any of its children have been touched.
Observe the activity's onPause() and onResume() to acknowledge that the activity is still being displayed.
You could then invoke a Runnable by posting it to a view using postDelayed(Runnable action, long delayMillis), being wary to remove it when the activity is paused or the timer should be reset using removeCallbacks(Runnable).
I solved the problem!!!
I used that event:
public boolean dispatchTouchEvent(MotionEvent ev)
{
super.dispatchTouchEvent(ev);
// cancel my Timer
return true;
}
Thanks!!
I have an application which is doing its work only when devices screen goes off. I have set up broadcast receiver (Intent.ACTION_SCREEN_OFF) and it works fine. I got record in my LOGCAT always when devices screen goes off. So far so good.
My onReceive code from ACTION_SCREEN_OFF uses some code calculating stuff, and all executes fine (When screen goes off). So far so good.
At the end of my onReceive code i'm starting new activity, but the onCreate of targeting activity is NOT always executing. (For example on my HTC Desire 2.3.7 works fine. On HTC Wildfire S 2.3.5, Xperia Arc S 2.3.4 it does not execute, and on Samsung Galaxy ACE 2.2.1 , it depends. Sometimes is executing sometimes isn't). My LOGCAT shows that onReceive executed till the end but Activity was not started. I'm using following code to starting this activity:
Intent startH_Activity = new Intent(getApplicationContext(), HandleActivity.class);
startH_Activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startH_Activity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(startH_Activity);
The important things to note:
I said that on some phones mentioned above it doesn't work. Well its not working immediately, like it should (when SCREEN_OFF fires ). Always activity starts like.. 10-15 minutes after screen went off (which is not acceptable)
When screen goes off and activity does not start , if I press POWER button on device it immediatelyfires off my target activity and app is working like normal. (again this is not acceptable. It should fire automatically).
When ANY device is connected to the PC it works like it should. Activity starts immediatelyafter screen goes off.
After reading a lot of Stack Overflow I realized that this is because MAYBE device goes to sleep. That's why it works like normal if i press POWER button, or Wakes up automatically after 10-15min because it synchronizes or something. So I used WAKELOCK.
//OnCreate Service
powMan = (PowerManager) getSystemService(POWER_SERVICE);
wake = powMan.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
//OnReceive (screen goes off)
wake.acquire();
But still without a success. (Am i doing wrong?) Even wake lock is acquired my activity won't show up on these devices.
Basically what I'm asking. How do i open usual activity when screen goes off? Or at least how to turn screen ON if activity won't start (remember, pressing on power button shows up my activity
I would really need some help now, because I'm getting really frustrated about this. Thank you for help.
You should be starting Service instead of Activity when screen goes off.
I would register yet another broadcast receiver and start the Activity when screen goes on (Intent.ACTION_SCREEN_ON).
Two issues:
1) How do you pass data from one receiver to another? What comes to my mind is either starting a Service or saving the information to a file (or shared preferences).
2) What happens if you have two events that must start an Activity? (E.g. "something started" and "something finished".) You must resolve this, either showing both events or just the latest one.
Note that the user can turn the screen on and off without unlocking the screen (Intent.ACTION_USER_PRESENT), and that if the phone is configured not to lock the screen, Intent.ACTION_USER_PRESENT does not happen.