GCM:另一个BIND_JOB_SERVICE权限错误 - IntentService to JobIntentServ



>问题:由于我现在需要以奥利奥为目标来提交应用程序,因此我必须将我的注册意图服务更改为从JobIntentService而不是IntentService继承。 我仍在使用GCM,但这应该没有区别。 请注意,这是 Xamarin C# 代码。

错误是我总是在我的静态 EnqueueWork 方法中收到一个异常,说:

Scheduled service ComponentInfo{com.emergencyuniversity.EUAlert/md58d0653b4094c2dbc798f6d984e1c1386.注册意图服务} 不需要android.permission.BIND_JOB_SERVICE权限

我已将 OnHandleIntent 更改为 OnHandleWork,现在我在以前调用 StartService 的地方调用静态 EnqueueWork 便利方法。

var intent = new Intent (this, typeof (RegistrationIntentService));
RegistrationIntentService.EnqueueWork(this, intent); // instead of StartService(intent)

我的排队工作,出现异常:

  public static void EnqueueWork(Context context, Intent work)
    {
        Java.Lang.Class cls = Java.Lang.Class.FromType(typeof(RegistrationIntentService));
        try
        {
            EnqueueWork(context, cls, GCMEUA_JOB_ID, work);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: {0}", ex.Message);
        }
    }

在清单中,我添加了:

<service android:name=".RegistrationIntentService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true" />

我也尝试导出 false,并将该权限放在一堆不同的地方。

由于编译器错误,我所做的另一个更改是删除以下内容:

public RegistrationIntentService() : base("RegistrationIntentService") { }

除了Android文档之外,我可能还阅读了所有可以想象到的帖子,包括:

https://android.jlelse.eu/keep-those-background-services-working-when-targeting-android-oreo-sdk-26-cbf6cc2bdb7f

https://medium.com/til-kotlin/jobintentservice-for-background-processing-on-android-o-39535460e060

工作服务不需要android.permission.BIND_JOB_SERVICE许可

为什么我仍然收到此错误?任何帮助将不胜感激。 谢谢。

好的,这就解决了。 最后一个问题已通过升级到 Xamarin.GooglePlayServices.Gcm 及其相关库的更高 NuGet 包得到解决。 现在一切正常。

最新更新