gpt4 book ai didi

android - 如何为广播接收器定义 IntentFilter

转载 作者:太空狗 更新时间:2023-10-29 14:29:06 26 4
gpt4 key购买 nike

因此,我正在尝试制作一个应用程序,在收到每条短信时都会显示消息提示。我希望应用程序只显示 toast ,我目前使用这段代码来显示它,但在应用程序运行时出现异常错误。我正在使用这段代码

BroadcastReceiver BR = new BroadcastReceiver() {

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

}
};


IntentFilter filter = new IntentFilter();

registerReceiver(BR, filter);

我很确定这是 intent 过滤器,但我不确定。

最佳答案

您必须在 list 中输入您的广播接收器,然后在我们为我们的 Activity 添加时添加 Intent 过滤器。这在运行时也是可能的。

关于android - 如何为广播接收器定义 IntentFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8585083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com