【问题标题】:Getting error while using pushwoosh and gcm library both使用 pushwoosh 和 gcm 库时出现错误
【发布时间】:2014-05-27 13:07:55
【问题描述】:

我使用 GCM 向用户发送单个消息。它工作正常,但是当我使用 pushwoosh 向所有注册设备发送消息时,我收到一个错误,错误是

Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/google/android/gcm/GCMBaseIntentService'

所以我删除了 GCM.jar 文件,因为在 PushWoosh 中他们已经提供了 GCMIntentService 类,但是我在 GCMIntentService.java 文件中遇到了另一个错误,如下所示

http://www.imagesup.net/?di=1414011958054

在这里,我收到建议删除参数以匹配 GCMIntentService 并且构造函数未定义。建议如下

public GCMIntentService() {
    // Call extended class Constructor GCMBaseIntentService
    super();
}

如果我删除 Config.GOOGLE_SENDER_ID 我们如何设置发件人 ID。

【问题讨论】:

    标签: android push-notification google-cloud-messaging pushwoosh


    【解决方案1】:

    GCMBaseIntentSerice 的这个构造函数是特定于上下文的。不设置发件人 ID 的构造函数,当发件人 ID 是特定于上下文的时很有用。使用此构造函数时,子类必须重写 getSenderIds(Context),否则 onHandleIntent(Intent) 等方法将在运行时抛出 IllegalStateException。查看官方文档http://developer.android.com/reference/com/google/android/gcm/GCMBaseIntentService.html#GCMBaseIntentService()

    覆盖该方法后,您可以在那里设置发件人ID。请参阅下面的代码。

    @Override
     protected String[] getSenderIds(Context context) {
         String[] ids = new String[1];
         ids[0] = Config.GOOGLE_SENDER_ID;
         return ids;
      }
    

    【讨论】:

      【解决方案2】:

      使用 Pushwoosh,您无需深入了解 GCMIntentService。 只需将项目 ID 放入应用程序标签下的 AndroidManifest.xml 中即可:

      <meta-data android:name="PW_APPID" android:value="4F0C807E51EC77.93591449" /> <meta-data android:name="PW_PROJECT_ID" android:value="A60756016005" />

      请参阅此处的第 4 步: http://www.pushwoosh.com/programming-push-notification/android/native-android-sdk-integration/

      【讨论】:

      • Pushwoosh 已经支持 GCM,只需从 Pushwoosh 获取 token 即可在 GCM 中使用!
      • 谢谢,我会检查的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      相关资源
      最近更新 更多