0

how to call a single activity(screen lock) of my lock screen app when my phone screen on and off, I am trying but not achive my target. please help me I am tired. I call activity from the Broadcast Receiver but this launches activity only my app is running when the app close the activity not launches. REciver is `

@Override
public void onReceive(Context context, Intent intent) { Toast.makeText(context, "BroadcastReceiver", Toast.LENGTH_SHORT).show();

    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        Intent lockIntent = new Intent(context, Lockview.class);
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);

        Toast.makeText(context, "Screen is lock", Toast.LENGTH_SHORT).show();

    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        Toast.makeText(context, "Screen is unlocked", Toast.LENGTH_SHORT).show();
    } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Intent lockIntent = new Intent(context, Lockview.class);
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);
        Toast.makeText(context, "Screen is book", Toast.LENGTH_SHORT).show();

    }`

and the MAnifest is `

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <receiver
        android:name=".AEScreenOnOffReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>`    and the activity where I trigger the Reciver is   ` BroadcastReceiver mybroadcast=new AEScreenOnOffReceiver();
    registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
    registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_SCREEN_OFF));

    registerReceiver(mybroadcast, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));` in the oncreate 
Mr Shahi
  • 3
  • 1
  • 7

1 Answers1

0

I have solved my Problem of launching the activity as a Screen lock direct from the Broadcast Receiver when the screen on. only by changing my Manifest receiver declaration as bellow <receiver android:name=".AEScreenOnOffReceiver" android:enabled="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.SCREEN_ON" /> <action android:name="android.intent.action.SCREEN_OFF" /> <category android:name="android.intent.category.HOME" /> <action android:name="android.intent.action.USER_PRESENT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver>

Mr Shahi
  • 3
  • 1
  • 7