I want to use wake lock to keep screen on by clicking widget on desktop
code here:
final PowerManager pm = (PowerManager)getSystemService(context.POWER_SERVICE);
PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "");
mWakeLock.acquire();
but it says getSystemService can not be used
if it is not "extends activity".
please help
When you extend
AppWidgetProviderall methods have aContextobject passed in.The
getSystemServicemethod is part of theContextclass in Android, so you will be able to get it using the passed in context.See: Context and getSystemService on Android Developers
Example code:
The example code uses the onEnabled method as an example, but this also works in the other methods like
onDisabled,onUpdate,onAppWidgetOptionsChangedetc.