Broadcast Receiver does not work through the manifest.



  • Broadcas tReceiver does not work through the manifest.

            <receiver android:name=".CallReciever" >
            <intent-filter>
                <action android:name="android.intent.action.SCREEN_ON"/>
            </intent-filter>
        </receiver>
    

    Code

        public class CallReciever extends BroadcastReceiver {
    
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("asd", "DA");
    }
    

    }

    But when it's switched off doesn't work.

    But if you put it in the line and add it.

        public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        registerReceiver(new CallReciever(), new IntentFilter(Intent.ACTION_SCREEN_ON));
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(new CallReciever());
    }
    

    }

    Then why did they put Manifest code on the off site?



  • I don't know what kind of web site you found a code for a manifesto, but in the documentation office. http://developer.android.com/intl/ru/reference/android/content/Intent.html#ACTION_SCREEN_ON () It is clearly written that this action cannot be captured from the manifesto:

    You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver()




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2