本文介绍了BroadcastReceiver Intent.ACTION_PACKAGE_ADDED/REMOVED Android Oreo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的广播接收器类,主要是其实现.
This is my broadcast receiver class and the implementation of it in main.
问题在于onReceive方法永远不会被调用.
Problem is that onReceive method never gets called.
class MyBroadcastReceiver : BroadcastReceiver() { override fun onReceive(p0: Context?, p1: Intent?) { Toast.makeText(p0, "It works", Toast.LENGTH_LONG).show() } } class MainActivity : AppCompatActivity() { ...... private var broadcastReceiver: MyBroadcastReceiver = MyBroadcastReceiver() override fun onCreate(savedInstanceState: Bundle?) { ...... registerReceiver(broadcastReceiver, IntentFilter().apply { addAction(Intent.ACTION_PACKAGE_ADDED) addAction(Intent.ACTION_PACKAGE_REMOVED) }) } override fun onDestroy() { super.onDestroy() unregisterReceiver(broadcastReceiver) } }请帮助.预先感谢.
推荐答案通常BroadcastReceiver需要设置许多步骤.
Usually the BroadcastReceiver needs a number of steps to be set up.
首先您没有将清单传递给清单吗?
First of all did yout pass to the manifest the receiver?
<receiver android:name=".MyBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.INPUT_METHOD_CHANGED" /> </intent-filter> </receiver>编辑 :请参阅此帖子,建议在ACTION_PACKAGE_FULLY_REMOVED或JobScheduler
Edit: Please see this post, where is suggested ACTION_PACKAGE_FULLY_REMOVED or JobScheduler
还尝试在模拟器上重新安装应用程序
try also to reinstall the app on the emulator
更多推荐
BroadcastReceiver Intent.ACTION
发布评论