将数据从 Activity 传递到 BroadcastReceiver
我有一个 BroadcastReceiver
,它为拨出电话的电话号码添加前缀,并且前缀由用户添加。
有什么方法可以将 Prefix (字符串变量)传递给 BroadcastReceiver
吗?
我的意思是,在我的应用程序被终止后,这个 BroadcastReceiver
仍然可以使用用户想要添加的 Prefix。
这是我的注册 BroadcastReceiver
代码,
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName componentName = new componentName(MyActivity.this,MyBroadcastReceiver.class);
pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
请帮助我解决这个问题。
I have an BroadcastReceiver
which add prefix to phone number of outgoing call and prefix is add by user.
Are there any way to pass Prefix (String variable) to BroadcastReceiver
?
I mean after my app is kill, this BroadcastReceiver
still working with Prefix that user wanted to add.
This is my code for register BroadcastReceiver
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName componentName = new componentName(MyActivity.this,MyBroadcastReceiver.class);
pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
Please help me regarding this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过意图,您可以这样做 -
传递类 -
接收类 -
在您的广播接收器类中包含
onReceive
方法并具有参数意图。这样它就可以用来从bundle中获取结果值。试试这个。我已将一些值传递给我的
BroadcastReceiver
类,如下所示。Through intent you can do like this -
Passing Class -
Received Class -
In your broadcast receiver class contains
onReceive
method and having arguments intent. So that it can be used to get the result value from bundle.Try this out. I've passed some values to my
BroadcastReceiver
class like this.通过使用 Intent,我们可以将数据从 Activity 传递到广播接收器。
By using Intent, we can passing the data from activity to broadcast receiver.
// getmessage 是挂起意图中的字符串值
,您必须在下面使用 -
PendingIntent.FLAG_CANCEL_CURRENT);
在广播接收器中
使用这个我将数据从活动传递到广播接收器。
希望这有帮助
// getmessage is string value
in pending intent you have to use below line-
PendingIntent.FLAG_CANCEL_CURRENT);
In broadcastreceiver
Using this i passing the data from activity to broadcast receiver.
Hope this helpful
通过intent你可以将字符串值传递给广播接收者
Through intent u can pass the string value to the broadcast reciever
我遇到了同样的问题,我在 mainfest 文件中注册了我的广播接收器,但不知道如何将前缀号码传递给我的广播接收器。有人知道该怎么做吗?
I got same problem, I register my broadcastreceiver in mainfest file, but don't know how to pass pre-fix number to my broadcast receiver. Anybody know how to do it?