我正在尝试在我的应用中实现 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/