Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从广播接收机呼叫中找出位置?_Android_Broadcastreceiver_Android Broadcastreceiver - Fatal编程技术网

Android 如何从广播接收机呼叫中找出位置?

Android 如何从广播接收机呼叫中找出位置?,android,broadcastreceiver,android-broadcastreceiver,Android,Broadcastreceiver,Android Broadcastreceiver,我正在做一些我不太熟悉的大项目。我有一个本地广播事件,它从脚本注册 context.registerReceiver(stReceiver, stIntents); private BroadcastReceiver stReceiver = new BroadcastReceiver() { @SuppressWarnings("unchecked") @Override public void onReceive(Context conte

我正在做一些我不太熟悉的大项目。我有一个本地广播事件,它从脚本注册

context.registerReceiver(stReceiver, stIntents);

private BroadcastReceiver stReceiver = new BroadcastReceiver() {

        @SuppressWarnings("unchecked")
        @Override
        public void onReceive(Context context, Intent intent) {

}
};

我想知道这个广播接收器是从哪里打来的?有没有办法找出哪个类
.sendBroadcast(intent)呼叫

我不能百分之百确定这是否有效,但请尝试一下。
You can put check 

like this

@Override
    public void onReceive(Context context, Intent intent) {

if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
//Do your part

}
}

In place of Intent.ACTION_MEDIA_BUTTON you can use your own action you mention in the intent filter while registering a receiver
使用Log语句在
onReceive
函数中打印
intent.getClass().getName()

由于意图是从调用类传递的,因此它将提供类名。

AFAIK
context.registerReceiver(stReceiver,stIntents)本身是
.sendBroadcast(intent)这里

.sendBroadcast(意图)用于全局广播。对于本地
注册表接收器(BroadcastReceiver,IntentFilter filter)
足以启动广播

 I need to find out where is this broadcastReceiver calling from?
所以在您的例子中
context.registerReceiver(stReceiver,stIntents)本身是起点

有关更多信息:


您可以检查动作的意图。并在项目中搜索操作


String action=intent.getAction()

谢谢。它没有给出调用类的名称。顺便说一句,即使解决方案不正确,也只有您能回答该问题。此调用与对象关联的类。所以这个问题的答案不正确。谢谢你的时间,但这不是我要找的。谢谢,但我有疑问。本地广播在API中还有一个名为sendBroadcast(Intent)的方法。那么它有什么用呢?