【发布时间】:2013-09-04 00:06:58
【问题描述】:
有没有办法在不使用清单文件中的 Intent-Filter 标记的情况下启动另一个包中定义的 Android 服务?由于某种原因,我无法更新包含服务的应用程序的清单文件。
【问题讨论】:
标签: android android-intent android-service
有没有办法在不使用清单文件中的 Intent-Filter 标记的情况下启动另一个包中定义的 Android 服务?由于某种原因,我无法更新包含服务的应用程序的清单文件。
【问题讨论】:
标签: android android-intent android-service
如果你知道确切的包名和服务名,你可以用它来创建一个 Intent。不过,该服务仍需要在其他清单中声明。
Intent intent = new Intent();
intent.setClassName("com.example.otherapplication", "com.example.otherapplication.ServiceName");
startService(intent);
【讨论】:
android:exported="true",否则您不能从另一个应用程序显式启动它