Android BackGround服务无法在Lollipop中使用启动服务

时间:2016-08-06 09:54:40

标签: android android-intent android-service android-intentservice explicit-intent

我有一个Android应用服务,用于推送在后台运行的通知。 它使用startService()调用intent;它在预版本中工作正常,但它不适用于棒棒糖。我不知道为什么它不起作用(因为服务意图必须在棒棒糖中明确)但是当我"试图使它explecit后台服务不起作用。如何解决它。

以下是调用服务的工作代码的一部分:

MainActivity

   Intent serviceIntent = new Intent("android.intent.action.START_SERVICE");
   this.startService(serviceIntent);

清单

 <service android:name=".MyService">
        <intent-filter>
            <action android:name="android.intent.action.START_SERVICE" />
            </intent-filter>
        </service>

1 个答案:

答案 0 :(得分:0)

设置你的packageName我认为它的工作。

intent.setPackage(this.getPackageName());