I'm just wondering if it's possible to register a broadcast receiver that detects on / off screens in the application manifest. The reason I donβt like the programmable method is because the application must work to detect such a thing, while: "Applications with broadcast receivers registered in the manifest should not start when Intent is broadcast to receivers to execute "(source: Professional Android 2 Application Development book)
My application is actually a lockscreen application that should work all the time using a programmable method: S
Is there any way?
I try the following in the manifest:
<receiver android:name=".MyBroadCastReciever"> <intent-filter> <action android:name="android.intent.action.SCREEN_OFF"/> <action android:name="android.intent.action.SCREEN_ON"/> </intent-filter> </receiver>
and a simple class MyBroadCastReciever:
public class MyBroadCastReciever extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.i("Check","Screen went OFF"); Toast.makeText(context, "screen OFF",Toast.LENGTH_LONG).show(); } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { Log.i("Check","Screen went ON"); Toast.makeText(context, "screen ON",Toast.LENGTH_LONG).show(); } } }
android screen broadcastreceiver
himura Feb 28 '12 at 7:21 2012-02-28 07:21
source share