Java Code Examples for com.xiaomi.mipush.sdk.MiPushClient#setAlias()

The following examples show how to use com.xiaomi.mipush.sdk.MiPushClient#setAlias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyApp.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public void setAlias() {
    LoginResult loginResult = SharedPreferencesMyUtil.queryToken(this);
    if (loginResult != null) {
        long storedUserId = loginResult.getUserId();
        if (storedUserId > 0) {
            MiPushClient.setAlias(this, storedUserId + "", null);
        }
    }
}
 
Example 2
Source File: SharedPreferencesMyUtil.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public static void storeToken(ContextWrapper contextWrapper, LoginResult loginResult) {
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_PASSPORT, 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putLong("userId", loginResult.getUserId());
    editor.putString("mobile", loginResult.getUsername());
    editor.putString("token", loginResult.getToken());
    editor.commit();
    if (loginResult.getUserId() > 0) {
        MiPushClient.setAlias(MyApp.getInstance(), loginResult.getUserId() + "", null);
        Log.i(MY_TAG, "MiPushClient_setAlias:alias=" + loginResult.getUserId() + "");
    }
}
 
Example 3
Source File: ThirdPushManager.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
    public void setAlias(Context context, String alias) {
        Logger.i("注册Third推送 setAlias  " + "regid : " + MiPushClient.getRegId(context));
//        if (!MiPushClient.getAllAlias(context).contains(alias)) {
            MiPushClient.setAlias(context,alias, null);
//        }
        //注册到服务器
        HttpUtil.registPush(alias, QTPushConfiguration.getPlatName() + "-" + Build.BRAND);
    }
 
Example 4
Source File: MiPushManager.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
    public void setAlias(Context context, String alias) {
        Logger.i("注册小米推送 setAlias  " + "regid : " + MiPushClient.getRegId(context));
//        if (!MiPushClient.getAllAlias(context).contains(alias)) {
            MiPushClient.setAlias(context,alias, null);
//        }
        //注册到服务器
        HttpUtil.registPush(alias, QTPushConfiguration.getPlatName());
    }
 
Example 5
Source File: XMAccountManager.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
public void setAccountAsAlias() {
    String xiaomiUserId = getXiaomiUserId(this.mAppCtx);
    if ((TextUtils.isEmpty(this.mUid) && !TextUtils.isEmpty(xiaomiUserId)) || (!TextUtils.isEmpty(this.mUid) && !this.mUid.equals(xiaomiUserId))) {
        if (TextUtils.isEmpty(this.mUid)) {
            MiPushClient.setAlias(this.mAppCtx, xiaomiUserId, null);
        } else {
            MiPushClient.unsetAlias(this.mAppCtx, this.mUid, null);
        }
        this.mUid = xiaomiUserId;
    }
}
 
Example 6
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
/**
 * 设置别名
 * <p>
 * 华为
 * <p>
 * 不支持alias的写法,所以只能用tag,tag只能放map,所以alias作为value,key为name
 * ==========
 * 极光 别名
 * <p>
 * "" (空字符串)表示取消之前的设置。
 * 每次调用设置有效的别名,覆盖之前的设置。
 * 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符(v2.1.6支持)@!#$&*+=.|。
 * 限制:alias 命名长度限制为 40 字节。(判断长度需采用UTF-8编码)
 * ==========
 * 小米 别名
 * <p>
 * 一个RegId可以被设置多个别名,如果设置的别名已经存在,会覆盖掉之前的别名。
 */
public static void setAlias(final Context context, String alias) {
    if (TextUtils.isEmpty(alias))
        return;
    if (RomUtil.rom() == PhoneTarget.EMUI) {
        Map<String, String> tag = new HashMap<>();
        tag.put("name", alias);
        com.huawei.android.pushagent.api.PushManager.setTags(context, tag);
        return;

    }
    if (RomUtil.rom() == PhoneTarget.MIUI) {
        MiPushClient.setAlias(context, alias, null);

        return;
    }

    if (RomUtil.rom() == PhoneTarget.JPUSH) {
        JPushInterface.setAlias(context, alias, new TagAliasCallback() {
            @Override
            public void gotResult(int i, String s, Set<String> set) {
                if (i == 0) { // 这里极光规定0代表成功
                    if (JPushReceiver.getPushListener() != null) {
                        JPushReceiver.getPushListener().onAlias(context, s);
                    }
                }
            }
        });
    }

}
 
Example 7
Source File: MiuiPushManager.java    From AndroidPush with Apache License 2.0 4 votes vote down vote up
@Override
public void setAlias(Context context, String alias) {
    MiPushClient.setAlias(context, alias, null);

}