该代码将在4月10日之后停止工作吗? GCM弃用

时间:2019-02-28 22:40:17

标签: google-cloud-messaging

此代码会

public class PushInstanceIDListenerService extends InstanceIDListenerService implements PushConstants {
public static final String LOG_TAG = "Push_InstanceIDListener";

@Override
public void onTokenRefresh() {
    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
    String senderID = sharedPref.getString(SENDER_ID, "");
    if (!"".equals(senderID)) {
        Intent intent = new Intent(this, RegistrationIntentService.class);
            startService(intent);
    }
}

4月10日GCM弃用后要停止工作吗?

1 个答案:

答案 0 :(得分:1)

是的,最好将代码迁移到FCM。请检查documentation

  

更改MyInstanceIDListenerService以扩展   FirebaseInstanceIdService,并更新代码以监听令牌   每当生成新令牌时,都会更新并获取令牌。

MyInstanceIDListenerService.java 之前

public class MyInstanceIDListenerService extends InstanceIDListenerService {

  ...

  @Override
  public void onTokenRefresh() {
      // Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
      Intent intent = new Intent(this, RegistrationIntentService.class);
      startService(intent);
  }
}

MyInstanceIDListenerService.java 之后

public class MyInstanceIDListenerService extends FirebaseInstanceIdService {

  ...

  /**
   * Called if InstanceID token is updated. This may occur if the security of
   * the previous token had been compromised. Note that this is also called
   * when the InstanceID token is initially generated, so this is where
   * you retrieve the token.
   */
  // [START refresh_token]
  @Override
  public void onTokenRefresh() {
      // Get updated InstanceID token.
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      Log.d(TAG, "Refreshed token: " + refreshedToken);
      // TODO: Implement this method to send any registration to your app's servers.
      sendRegistrationToServer(refreshedToken);
  }

}