1

I have two receivers in manifest file. One is working one is not. Can I have multiple receivers in manifest ?

<receiver android:name=".services.MobileViaNetReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

<receiver android:name=".services.SessionManager">
    <intent-filter>
        <action android:name="android.intent.action.SCREEN_OFF"></action>
        <action android:name="android.intent.action.ACTION_SHUTDOWN"></action>
        <action android:name="android.intent.action.SCREEN_ON"></action>
    </intent-filter>
</receiver>

UPDATE >>>>>>>>>>>>>>>>>>>>>>

ACTION SHUTDOWN IS WORKING FOR ME. Following is a code for SessionManager

public class SessionManager extends BroadcastReceiver{
Date timeOff;
Date timeOn;


@Override
public void onReceive(Context context, Intent intent) {     

    if( "android.intent.action.SCREEN_OFF".equals(intent.getAction())) {
        timeOff = Calendar.getInstance().getTime();
    } 

    if( "android.intent.action.ACTION_SHUTDOWN".equals(intent.getAction())) {
        Functions.logout(context);
    } 

    if( "android.intent.action.SCREEN_ON".equals(intent.getAction())) {
        timeOn = Calendar.getInstance().getTime();
        long diffInMs = timeOn.getTime()-timeOff.getTime();

        // convert it to Minutes
        long diffInMins = TimeUnit.MILLISECONDS.toMinutes(diffInMs);

        if ((int) (diffInMins) > 15) {
            Functions.logout(context);

        } else {
            Log.i("MobileViaNetReceiver", "User still active");
        }
    }   
}

}

SnowyTracks
  • 1,965
  • 15
  • 21
user533844
  • 2,053
  • 7
  • 36
  • 43

2 Answers2

0

OK, as you definitely get SHUTDOWN intent, your broadcast receiver IS working. But it does not mean that SCREEN_ON and SCREEN_OFF are actually being sent and delievered to your application. Here is some explanation about this condittion:

android.intent.action.SCREEN_ON doesn't work as a receiver intent filter

Community
  • 1
  • 1
Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
0

Try adding the following inside of the intent filter for your receiver that is not working.

<category android:name="android.intent.category.DEFAULT" />
Bobbake4
  • 24,509
  • 9
  • 59
  • 94