android.intent.action.SCREEN_OFF - android

I am trying to detect Screen backlight On / Off.
I've found android.intent.action.SCREEN_OFF related its event.
But I don't know how to use this.
Can you suggest me about how to detect screen backlight on / off ?
I missing some example or sample code.
Thanks in advance.

If you still need to use a BroadCastReceiver, you have to register it in code using the registerReceiver(receiver, filter) on one of your Activities.
The intents do not fire if you register them in the Manifest.

Create a BroadCastReciever, Add an Intent Filter including your Intent (android.intent.action.SCREEN_OFF).
Just Override the OnRecieve function in the BroadcastReciver with your code.
Be Sure to include the BroadcastReciever in the Manifest File!
good luck! :)

I think you can have a look at this class. The method isScreenOn() might be what you need.

Related

Declaring actions through RegisterReceiver or in AndroidManifest

I want to start service if screen is on.I think I have to use Intent.ACTION_SCREEN_ON. But I'm not sure where should I declare it in AndroidManifest or through RegisterReceiver method? As I understood if I will declare this action in the AndroidManifest my service will be started even if user hasn't reached specific point in my app cause action was committed. So if want to start service after user has reached that specific point and also screen is on I should use RegisterReceiver method, right?
But I'm not sure where should I declare it in AndroidManifest or through RegisterReceiver method?
ACTION_SCREEN_ON only works via registerReceiver().

whats the mobilenetwork-manager equivalent of the WifiManager

I need to add an action to an IntentFilter for detecting changes in the mobile-network.. so basically what I need is an equivalent of WifiManager.SUPPLICANT_STATE_CHANGED_ACTION but for the MobileNetwork. but I'm not really sure what the class I'm looking for is called. Any ideas?
Seems ConnectivityManager would help. It has some description in the documentation. Briefly, I think You need to:
Register BroadcastReceiver with ConnectivityManager.CONNECTIVITY_ACTION
Check changed network(or all connections)

Get BroadcastRecevier Object from ResloveInfo

I am stuck up just now; issue is my one of activity has register one private broadcastReceiver and I need to unregister it and as usual I cannot change that file.
My approach is get all broadcast receiver information () for that intent by Package Manager.queryBraodcastReceiver method.
Now I want to get broadcast receiver object from it.
Is there any other approach to work out this problem?
Is there any other approach to work out this problem?
Fix the activity to unregister its receiver. You cannot do this from anywhere else in your app.

How to Triggering code in background in android?

I want to trigger specific code snippet at everyday 10.00AM while app will minimized pls help me?
You need to use Alarm Manager Class.
You can find suitable example HERE.
The easiest way to achieve this is setting up an AlarmManager that will fire your intent at the time you set it to.Inside your intent you can do whatever code you want.Else setting up a background service could be a good alternative,even tough takes a little more coding

Android widget onUpdate() issues

I have a widget in my app and it gets screwed up (one of it's resources, a counter, has to be visible only if greater than 0 and it does not react anymore to a press) every time I install/remove/update a 3rd party app because the onUpdate() method probably gets called and the code I have written is not executed properly.
It is certain that the AppWidgetManager reacts to the following intents:
android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_RESTARTED
But how can I make the widget not react to such intents, it is not even registered for them in the manifest?
try adding those actions to the manifest .. and avoid reacting to them in the onReceive method, it's somehow trivial solution but it will do !
Have you tried overriding the onReceive method and check for the intent? I have provided a quick example.
if(intent.getAction().compareTo("android.intent.action.PACKAGE_ADDED") != 0) {
//do something cool;
}
This should allow you to check the incoming intent and filter out what you don't want

Categories

Resources