android 接口设置,基本设置相关接口

  • Post author:
  • Post category:其他


SDK初始化

初始化推送SDK配置,必须在application的onCreate方法中执行,主进程和channel进程必须都执行到

方法定义public static void init(Context appContext)

public static void init(Context appContext, boolean enableChannelProcess)

public static void init(Context appContext, String appKey, String appSecret)

public static void init(Context appContext, String appKey, String appSecret, boolean enableChannelProcess)

public static void init(PushInitConfig pushInitConfig)

// 初始化配置,针对需要多项配置的情况

public class PushInitConfig {

public static class Builder {

// application配置,必填

public Builder application(Application application)

// appKey 动态配置,使用manifest配置时 不用设置

public Builder appKey(String appKey)

// appSecret 动态配置,使用manifest配置时 不用设置

public Builder appSecret(String appSecret)

// 禁用channel进程配置,特殊场景使用,不必须

public Builder disableChannelProcess(boolean disableChannelProcess)

// 定期循环拉起channel进程配置,特殊场景使用,不必须

public Builder loopStartChannel(boolean enable)

// 定期循环拉起channel进程间隔配置 单位ms,特殊场景使用,不必须

public Builder loopInterval(long interval)

// 构建初始化配置

public PushInitConfig build()

}

}

参数说明参数类型是否必填说明contextContext是应用上下文(需要ApplicationContext)

appKeyString否当没有在manifest中配置appKey时,此处必须填写

appSecretString否当没有在manifest中配置appSecret时,此处必须填写

enableChannelProcessboolean否是否使用静默通道,默认是。

静默通道用于应用在后台时接收推送,会采取一些提高存活率的措施,如果只需要应用在前台时接收推送,可以不使用静默通道

pushInitConfigPushInitConfig是替代其他init方法,统一所有参数配置到此类。

代码示例// 一般情况

PushInitConfig config = new PushInitConfig.Builder()

.application(this)

.build();

PushServiceFactory.init(config);

// 需要代码动态配置appKey和appSecret

PushInitConfig config = new PushInitConfig.Builder()

.application(this)

.appKey(“填入应用的appKey”)

.appSecret(“填入应用的appSecret”)

.build();

PushServiceFactory.init(config);

// 特殊场景 需要禁止channel

PushInitConfig config = new PushInitConfig.Builder()

.application(this)

.disableChannelProcess(SpUtils.disableChannel(applicationContext))

.build();

PushServiceFactory.init(config);

// 特殊场景 需要定时拉起channel

PushInitConfig config = new PushInitConfig.Builder()

.application(this)

.loopStartChannel(true)

.loopInterval(30 * 1000)

.build();

PushServiceFactory.init(config);