0

I am trying to use a receiver to receive a broadcast when the device screen is on, the problem is if the phone is off and someone calls the phone then the receiver gets a "SCREEN_ON" event broadcast,

how can i ignore the screen_on event if the phone is receiving a call?

My Maniftest.xml

    <receiver
        android:name="com.lockscreen.wipe.MainActivity$DeviceAdminSampleReceiver"
        android:description="@string/sample_device_admin_description"
        android:label="@string/sample_device_admin"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_admin_sample" />

        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            <action android:name="android.intent.action.SCREEN_ON" />
        </intent-filter>
    </receiver>

My Receiver.java

package com.lockscreen.wipe;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class LockscreenIntentReceiver extends BroadcastReceiver {

    // Handle actions and display Lockscreen
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)
                || intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            start_lockscreen(context);
        }

    }

    // Display lock screen
    private void start_lockscreen(Context context) {
        Intent mIntent = new Intent(context, LockScreenActivity.class);
        mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(mIntent);
    }

}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
WalksAway
  • 2,769
  • 2
  • 20
  • 42

1 Answers1

0

You can to track the states of "calls". Take a look here: How to detect incoming calls, in an Android device?

One approach could be to abort your start_lockscreen() once you receive the action TelephonyManager.CALL_STATE_RINGING

Arseny Levin
  • 664
  • 4
  • 10