0

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

错误是我的静态 EnqueueWork 方法中总是出现异常:

定时服务ComponentInfo{com.emergencyuniversity.EUAlert/md58d0653b4094c2dbc798f6d984e1c1386.RegistrationIntentService}不需要android.permission.BIND_JOB_SERVICE权限

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

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

我的 EnqueueWork,得到了异常:

  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" />

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

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

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

JobService 不需要 android.permission.BIND_JOB_SERVICE 权限

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

4

1 回答 1

0

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

于 2018-08-09T19:31:01.443 回答