无法从包含库的应用程序启动意图
问题描述:
嗨:我想启动位于连接库项目中的服务。所有有关的课程都在图书馆中。无法从包含库的应用程序启动意图
的服务是从位于库的活动名为:
Intent serviceIntent = new Intent();
serviceIntent.setAction("org.example.library.MY_ACTION");
startService(serviceIntent);
在清单文件 - 既在图书馆和以应用为它指出:
<service android:name="org.example.library.SomeLibraryClass">
<intent-filter>
<action android:name="org.example.library.MY_ACTION" />
</intent-filter>
</service>
无法启动服务Intent {act = org.example.android.SomeLibraryClass(has extras)}:找不到
看起来Android似乎在寻找在应用程序中但不在库中的类。任何人都有过这种行为?
答
调用库中定义的意图时,您需要指定应用程序的包:
Intent serviceIntent = new Intent();
serviceIntent.setAction("org.example.library.MY_ACTION");
serviceIntent.setPackage("org.example.application");
startService(serviceIntent);
你的库添加到您的项目? – Falmarri 2010-08-30 02:28:10
是的。所在的主要活动已成功启动。但是开始活动的另一个意图导致了上述结果。 – Sney 2010-08-30 16:45:06