此代码会在 4 月 10 日后停止工作吗? GCM 弃用

will this code stop working after April 10? GCM deprecation

将此代码

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 后停止工作?

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

Change MyInstanceIDListenerService to extend FirebaseInstanceIdService, and update code to listen for token updates and get the token whenever a new token is generated.

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);
  }

}