【问题标题】:adb shell broadcast not work while sendBroadcast(intent) works welladb shell 广播不起作用,而 sendBroadcast(intent) 运行良好
【发布时间】:2016-08-26 21:19:09
【问题描述】:

我有一个类注册接收器,如下所示:

onStart() {
    IntentFilter filter = new IntentFilter();
    filter.addAction("ActionName");
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
}

onStop() {
    localBroadcastManager.unregisterReceiver(receiver);
}

private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(LOG_TAG, String.format("Broadcast received [action=%s]", intent.getAction()));
    }
}

在其他一些类中,我使用代码来广播 Intent。效果很好。

Intent intent = new Intent("ActionName");
intent.putExtra("Extra", someObject);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);

但是,我尝试使用 adb shell 来触发此功能。它从不响应。

adb shell am broadcast -a ActionName -e Extra someObject

我是否正确使用 add 命令?

【问题讨论】:

    标签: android android-intent broadcastreceiver adb broadcast


    【解决方案1】:

    LocalBroadcastManager 是注册 Intent 广播并将其发送到进程中的本地对象的助手。这与Contenxt.sendBroadcast() 相比有数量限制,其中之一是其他应用程序无法将这些广播发送到您的应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 2019-03-23
      • 2011-07-29
      • 2011-01-14
      相关资源
      最近更新 更多