All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.leancloud.oppo.AVMixPushManager Maven / Gradle / Ivy

package cn.leancloud.oppo;

import android.content.Context;
import java.util.List;

import cn.leancloud.AVException;
import cn.leancloud.AVInstallation;
import cn.leancloud.AVLogger;
import cn.leancloud.AVOPPOPushAdapter;
import cn.leancloud.callback.SaveCallback;
import cn.leancloud.convertor.ObserverBuilder;
import cn.leancloud.utils.LogUtil;
import cn.leancloud.utils.StringUtil;

import com.heytap.msp.push.HeytapPushManager;

/**
 * Created by wli on 16/6/27.
 */
public class AVMixPushManager {
  private static final AVLogger LOGGER = LogUtil.getLogger(AVMixPushManager.class);

  public static final String MIXPUSH_PROFILE = "deviceProfile";

  public static String oppoDeviceProfile = "";

  /**
   * Oppo push
   */

  /**
   * register Oppo Push.
   *
   * @param context context
   * @param appKey oppo application key
   * @param appSecret oppo application secret
   * @param callback callback
   * @return
   */
  public static boolean registerOppoPush(Context context, String appKey, String appSecret,
                                         AVOPPOPushAdapter callback) {
    if (null == context || StringUtil.isEmpty(appKey) || StringUtil.isEmpty(appSecret)) {
      LOGGER.e("invalid parameter. context=" + context + ", appKey=" + appKey);
      return false;
    }
    HeytapPushManager.init(context, true);
    if (!isSupportOppoPush(context)) {
      LOGGER.e("current device doesn't support OPPO Push.");
      return false;
    }
    HeytapPushManager.register(context, appKey, appSecret, callback);
    HeytapPushManager.requestNotificationPermission();
    return true;
  }

  /**
   * register oppo push
   * @param context context
   * @param appKey oppo application key
   * @param appSecret oppo application secret
   * @param profile profile string.
   * @param callback callback.
   * @return
   */
  public static boolean registerOppoPush(Context context, String appKey, String appSecret,
                                         String profile, AVOPPOPushAdapter callback) {
    oppoDeviceProfile = profile;
    return registerOppoPush(context, appKey, appSecret, callback);
  }


  /**
   * judgement if support oppo push or not.
   *
   * @param context
   * @return
   */
  public static boolean isSupportOppoPush(Context context) {
    return HeytapPushManager.isSupportPush();
  }

  /**
   * pause oppo push
   */
  public static void pauseOppoPush() {
    HeytapPushManager.pausePush();
  }

  /**
   * resume oppo push
   */
  public static void resumeOppoPush() {
    HeytapPushManager.resumePush();
  }

  /**
   * set oppo push time.
   * @param weekDays
   * @param startHour
   * @param startMinute
   * @param endHour
   * @param endMinute
   */
  public static void setOppoPushTime(List weekDays, int startHour, int startMinute,
                                     int endHour, int endMinute) {
    HeytapPushManager.setPushTime(weekDays, startHour, startMinute,
        endHour, endMinute);
  }

  /**
   * set oppo push aliases.
   * @param aliases
   */
  @Deprecated
  public static void setOppoAliases(List aliases) {
  }

  /**
   * unset oppo push aliases.
   * @param alias
   */
  @Deprecated
  public static void unsetOppoAlias(String alias) {
  }

  /**
   * get oppo aliases.
   */
  @Deprecated
  public static void getOppoAliases() {
  }

  /**
   * set oppo push account.
   * @param account
   */
  @Deprecated
  public static void setOppoUserAccount(String account) {
  }

  /**
   * unset oppo push accounts.
   * @param accounts
   */
  @Deprecated
  public static void unsetOppoUserAccouts(List accounts) {
  }

  /**
   * get oppo push accounts.
   */
  @Deprecated
  public static void getOppoUserAccounts() {
  }

  /**
   * set oppo push tags.
   * @param tags
   */
  @Deprecated
  public static void setOppoTags(List tags) {
  }

  /**
   * unset oppo push tags.
   * @param tags
   */
  @Deprecated
  public static void unsetOppoTags(List tags) {
  }

  /**
   * retrieve oppo push tags.
   */
  @Deprecated
  public static void getOppoTags() {
  }

  /**
   * get oppo push status
   */
  public static void getOppoPushStatus() {
    HeytapPushManager.getPushStatus();
  }

  /**
   * get oppo notification status.
   */
  public static void getOppoNotificationStatus() {
    HeytapPushManager.getNotificationStatus();
  }

  /**
   * 取消混合推送的注册
   * 取消成功后,消息会通过 LeanCloud websocket 发送
   */
  public static void unRegisterMixPush() {
    AVInstallation installation = AVInstallation.getCurrentInstallation();
    String vendor = installation.getString(AVInstallation.VENDOR);
    if (!StringUtil.isEmpty(vendor)) {
      installation.put(AVInstallation.VENDOR, "lc");
      installation.saveInBackground().subscribe(ObserverBuilder.buildSingleObserver(new SaveCallback() {
        @Override
        public void done(AVException e) {
          if (null != e) {
            printErrorLog("unRegisterMixPush error!");
          } else {
            LOGGER.d("Registration canceled successfully!");
          }
        }
      }));
      HeytapPushManager.unRegister();
    }
  }

  private static void printErrorLog(String error) {
    if (!StringUtil.isEmpty(error)) {
      LOGGER.e(error);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy