BroadcastReceiver Intent.ACTION

编程入门 行业动态 更新时间:2024-10-25 04:23:40
本文介绍了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

本文发布于:2023-11-27 04:34:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:BroadcastReceiver   Intent   ACTION

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!