4

我的嵌套意图服务定义如下:

package com.my.package;

... // Bunch of imports

public class MyNotifier

    ... // Bunch of variables

    public class MissedCallIntentService extends IntentService {

        private static final String TAG = "MissedCallIntentService";

        public MissedCallIntentService() {
            super("MissedCallIntentService");
            Log.i(TAG, "Creating intent service.");
        }

        @Override
        public void onHandleIntent(Intent intent) {
            Log.i(TAG, "Handling intent service.");
        }
    }

    // Test my nested intent filter
    public MyNotifier(Context app) {
        mApp = app;
        Log.i(LOG_TAG, "Going to start intent service.");
        Intent intent = new Intent(mApp, MissedCallIntentService.class);
        mApp.startService(intent);
    }

    ... // Bunch of functions
}

我的 AndroidManifest.xml 文件包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>  
    // Protected Broadcasts
    // Permissions
    <application ...>
        <service android:name="com.my.package.MyNotifier.MissedCallIntentService" >
        </service>

        <activity android:name="ActivityOne"    
            android:label="@string/activity_one"
            <intent-filter>
                ...
            </intent-filter>
        </activity>

        <activity android:name="ActivityTwo"
            android:label="@string/activity_two"
            <intent-filter>
                ...
            </intent-filter>
        </activity>

        <activity android:name="ActivityThree"
            android:label="@string/activity_three"
            <intent-filter>
                ...
            </intent-filter>
        </activity>
    </application>
</manifest>

在构建我的应用程序然后将其推送到手机并运行它之后,这就是我所看到的。

$ make_magic && adb remount && adb push MyApp.apk /system/app/ && adb reboot && adb logcat | grep 'intent\ service'
make: Leaving directory `BuildDir'
remount succeeded
6149 KB/s (6036528 bytes in 0.958s)
- waiting for device -
I/MyNotifier( 1184): Going to start intent service.

我应该看到:

I/MyNotifier( XXXX): Going to start intent service.
I/MissedCallIntentService( XXXX): Creating intent service.
I/MissedCallIntentService( XXXX): Handling intent service.

这就是我的问题的重点。我需要添加什么才能调用我的意图服务?

4

1 回答 1

6

将嵌套的内部类声明为静态或在它自己的类中定义它(如果这样做,请更新清单)

如果您引用内部类,则引用应该是

<service android:name="com.my.package.MyNotifier$MissedCallIntentService" />

(注意美元符号)

于 2013-10-01T21:49:38.100 回答