【问题标题】:GCM: Yet another BIND_JOB_SERVICE permission error -- IntentService to JobIntentServiceGCM:又一个 BIND_JOB_SERVICE 权限错误——IntentService 到 JobIntentService
【发布时间】:2019-01-14 21:43:48
【问题描述】:

问题:由于我现在需要以 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" />

我也尝试过导出 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

JobService does not require android.permission.BIND_JOB_SERVICE permission

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

【问题讨论】:

  • "我仍在使用 GCM,但这应该没什么区别。" - 是的。 GCM 现已正式弃用。鼓励开发人员迁移到 FCM 的原因仅仅是因为它是最新版本。它包含对 GCM 期间存在的错误的修复。如果您仍然继续使用 GCM,则无法保证它的行为。
  • 我同意我需要迁移到 FCM,而且我很快就会这样做,但即使它在 4 月被弃用,我也无法相信 Firebase 会让我感到兴奋和干燥。我的 EnqueueWork 代码一定有问题。
  • 话虽如此,我尝试的第一件事是将 GCM 消息的优先级提高到高,因为这应该将您列入白名单。但是,这不起作用,所以我想知道这是否仅适用于 FCM。但我仍然认为有可能解决这个问题。我只是还没有弄清楚。
  • 嗯——这是一个过程。通过将 Service(Name = "MyPackage.RegistrationIntentService", Permission = "android.permission.BIND_JOB_SERVICE", Exported = true)] 放到服务的 C# 文件中,克服了 BIND_JOB_SERVICE 错误。下一个错误是 com.google.android.gms.iid.zzd 无法访问 android.support.v4.content.ContextCompat ,这意味着我无疑必须更新 GooglePlayServices nuget 等内容。这也不起作用。最终,我想我应该能够克服这一切。

标签: android google-cloud-messaging android-permissions android-8.0-oreo jobintentservice


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 2018-07-26
    • 2019-04-14
    • 1970-01-01
    • 2015-02-02
    相关资源
    最近更新 更多