Activity Recognition API does not work continuously

后端 未结 2 1503
遥遥无期
遥遥无期 2021-01-24 13:38

I\'m testing Activity Recognition API in 2 apps : Google sample code and implementation of this code in my app.

The problem is both apps keeps getting activity recognit

2条回答
  •  清酒与你
    2021-01-24 14:30

    Even registering broadcast receiver in Manifest file,you need to register in dynamically in Oreo+ otherwise it will not work. Try this.Add this code in main activity or in startCommand in Service.It worked for me.I have tested this code on Android 10 too..worked perfectly.You need not to register broadcast receiver in Manifest file.

    @Override
        protected void onStart() {
            super.onStart();
            IntentFilter intentFilter=new IntentFilter(Constants.BROADCAST_DETECTED_ACTIVITY);
        intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
            registerReceiver(broadcastReceiver,intentFilter);
    
        }
    

提交回复
热议问题