Exemplo n.º 1
0
  public static void removeWpComUserRelatedData(Context context) {
    // cancel all Volley requests - do this before unregistering push since that uses
    // a Volley request
    VolleyUtils.cancelAllRequests(requestQueue);

    NotificationsUtils.unregisterDevicePushNotifications(context);
    try {
      GCMRegistrar.checkDevice(context);
      GCMRegistrar.unregister(context);
    } catch (Exception e) {
      AppLog.v(T.NOTIFS, "Could not unregister for GCM: " + e.getMessage());
    }

    // delete wpcom blogs
    wpDB.deleteWordPressComBlogs(context);

    // reset default account
    AccountHelper.getDefaultAccount().signout();

    // reset all reader-related prefs & data
    AppPrefs.reset();
    ReaderDatabase.reset();

    // Reset Stats Data
    StatsDatabaseHelper.getDatabase(context).reset();

    // Reset Simperium buckets (removes local data)
    SimperiumUtils.resetBucketsAndDeauthorize();
  }
Exemplo n.º 2
0
  public static void registerForCloudMessaging(Context context) {
    String regId = gcmRegisterIfNot(context);

    // Register to WordPress.com notifications
    if (AccountHelper.isSignedInWordPressDotCom()) {
      if (!TextUtils.isEmpty(regId)) {
        // Send the token to WP.com in case it was invalidated
        NotificationsUtils.registerDeviceForPushNotifications(context, regId);
        AppLog.v(T.NOTIFS, "Already registered for GCM");
      }
    }

    // Register to Helpshift notifications
    HelpshiftHelper.getInstance().registerDeviceToken(context, regId);
    AnalyticsTracker.registerPushNotificationToken(regId);
  }
Exemplo n.º 3
0
 /**
  * Check if user has valid credentials, and that at least 2 minutes are passed since the last
  * ping, then try to update the PN token.
  */
 private void updatePushNotificationTokenIfNotLimited() {
   // Synch Push Notifications settings
   if (isPushNotificationPingNeeded() && AccountHelper.isSignedInWordPressDotCom()) {
     String token = null;
     try {
       // Register for Google Cloud Messaging
       GCMRegistrar.checkDevice(mContext);
       GCMRegistrar.checkManifest(mContext);
       token = GCMRegistrar.getRegistrationId(mContext);
       String gcmId = BuildConfig.GCM_ID;
       if (gcmId == null || token == null || token.equals("")) {
         AppLog.e(T.NOTIFS, "Could not ping the PNs backend, Token or gmcID not found");
       } else {
         // Send the token to WP.com
         NotificationsUtils.registerDeviceForPushNotifications(mContext, token);
       }
     } catch (Exception e) {
       AppLog.e(T.NOTIFS, "Could not ping the PNs backend: " + e.getMessage());
     }
   }
 }