android - BroadcastReceiver 不会对外部 Intent 使用react

标签 android android-intent broadcastreceiver

我正在尝试在我的应用中实现 Tasker 支持。我已经在 Manifest 文件中声明了 intent-filter 并编写了 Receiver,但它不起作用(没有记录任何内容,我的应用程序不会对这些 intent 使用react)。

我已经测试过它像这样从 tasker 发送 Intent :

操作:START_SERVICE

包:com.example.appname

list 声明:

<receiver android:name="ExIntentReceiver">  
  <intent-filter>
    <action android:name="com.example.appname.START_SERVICE" />
    <action android:name="com.example.appname.STOP_SERVICE" />
  </intent-filter>
</receiver>

接收者:

Public class ExtIntentReceiver extends BroadcastReceiver {


 @Override
   public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
  if(action.equals("com.example.appname.START_SERVICE"))    {
        Log.v("service", "is started");
      } else if(action.equals("com.example.appname.STOP_SERVICE"))  {
          Log.v("service", "is stopped");
      }

   }

}

最佳答案

其实我看到一个地方可能是一个原因。当您发送 Intent 时,您指定包名称 com.example.appname,但 AndroidManifest.xml 中指定的是什么?如果您在 Intent 中使用包名称,则此名称必须与接收应用的 AndroidManifest.xml 中的包名称相匹配。

关于android - BroadcastReceiver 不会对外部 Intent 使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16107112/

相关文章:

android - 在 ListView 中显示来自数据库的数据

android - 通过Kotlin使用Intent Extras获取房间数据

android - 是否可以在 android 中以编程方式阻止/禁用出厂重置?

android - 如何获取未在 Android Activity 中单击的按钮的时间

android - PendingIntent.getBroadcast() 永远不会返回 null

android - 没有 MapView 的地理编码器

android - 在 Canvas 上用图形编号替换数字编号

android - 如何从android中的VRPanorama View中删除信息标签

android - 从服务到 Activity 的 sendBroadcast() 处出现 NullPointerException

android - BroadcastReceiver 生命周期