找到你要的答案

Q:startService with explicit intent is not working to start framework service

Q:显式意图启动服务工作不启动框架服务

I have added MyService in the android framework path.

android/framework/base/services/java/com/xxxx/server/ 

Calling startService() of MyService, from test application is working fine with implicit intent. But explicit is not working with warning message

"Unable to start service".

I have used flag android:exported="true" and package name "com.xxxx.server", class name "com.xxxx.server.MyService"

Please let me know how do we use explicit intent with framework service.

code in frameworks/base/core/res/AndroidManifest is

    <service android:name="com.xxxx.server.MyService"
            android:exported="true">
    <intent-filter>
            <action android:name="com.test.MyService" />
    </intent-filter>
    </service>

code for starting service from test app

    Intent intent = new Intent();
    intent.setClassName("com.xxxx.server", "com.xxxx.server.MyService");
    intent.setComponent(new ComponentName(
                    "com.xxxx.server", "com.xxxx.server.MyService"));*/
    startService(intent);

我说我在Android框架的路径。

android/framework/base/services/java/com/xxxx/server/ 

打电话的startservice() MyService,从测试的应用是与隐式意图良好的工作。但显式不使用警告消息

“无法启动服务”。

I have used flag android:exported="true" and package name "com.xxxx.server", class name "com.xxxx.server.MyService"

请让我知道我们如何使用显式的意图与框架服务。

代码的框架/库/核心/物/句话是

    <service android:name="com.xxxx.server.MyService"
            android:exported="true">
    <intent-filter>
            <action android:name="com.test.MyService" />
    </intent-filter>
    </service>

从测试应用程序启动服务代码

    Intent intent = new Intent();
    intent.setClassName("com.xxxx.server", "com.xxxx.server.MyService");
    intent.setComponent(new ComponentName(
                    "com.xxxx.server", "com.xxxx.server.MyService"));*/
    startService(intent);
answer1: 回答1:

if you are calling startService/startActivity outside of an activity, you need context

context.startService(intent);

如果你调用startService / startActivity的活动外,你需要语境

context.startService(intent);
android  android-intent