Gcm RegistrationIntentService不适用于Android版本8 oreo

时间:2018-03-16 07:05:10

标签: android google-cloud-messaging

public class RegistrationIntentService extends JobIntentService {


private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};
private static Context context1;
private String SENDER_ID;
private AppActivity appActivityContext;
private SharedPreferences.Editor editor;


public RegistrationIntentService() {
    super();
}

@Override
protected void onHandleWork(@NonNull Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);


    try {


        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);

}
...
}

我实现了jobintentservice但它不起作用。只调用默认构造函数中的super()。不调用OnHandleWork 在8以下的Android版本上正常工作

0 个答案:

没有答案