com.xiaomi.mipush.sdk.MiPushClient Java Examples

The following examples show how to use com.xiaomi.mipush.sdk.MiPushClient. 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: AVMiPushMessageReceiver.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 注册结果
 */
@Override
public void onReceiveRegisterResult(Context context, com.xiaomi.mipush.sdk.MiPushCommandMessage miPushCommandMessage) {
  super.onReceiveRegisterResult(context, miPushCommandMessage);
  String command = miPushCommandMessage.getCommand();
  List<String> arguments = miPushCommandMessage.getCommandArguments();
  String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
  if (com.xiaomi.mipush.sdk.MiPushClient.COMMAND_REGISTER.equals(command)) {
    if (miPushCommandMessage.getResultCode() == com.xiaomi.mipush.sdk.ErrorCode.SUCCESS) {
      updateAVInstallation(cmdArg1);
    } else {
      LOGGER.d("register error, " + miPushCommandMessage.toString());
    }
  } else {
  }
}
 
Example #2
Source File: DemoMessageReceiver.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
    Log.v(MyApp.TAG,
            "onReceiveRegisterResult is called. " + message.toString());
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String log;
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
            log = context.getString(R.string.register_success);
        } else {
            log = context.getString(R.string.register_fail);
        }
    } else {
        log = message.getReason();
    }

    Message msg = Message.obtain();
    msg.obj = log;
    MyApp.getHandler().sendMessage(msg);
}
 
Example #3
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 6 votes vote down vote up
/**
 * 获取唯一的token
 *
 * @param context
 * @return
 */
public static TokenModel getToken(Context context) {
    if (context == null)
        return null;
    TokenModel result = new TokenModel();
    result.setTarget(RomUtil.rom());
    if (RomUtil.rom() == PhoneTarget.EMUI) {
        result.setToken(HWReceiver.getmToken());
    }
    if (RomUtil.rom() == PhoneTarget.MIUI) {
        result.setToken(MiPushClient.getRegId(context));
    }

    if (RomUtil.rom() == PhoneTarget.JPUSH) {
        result.setToken(JPushInterface.getRegistrationID(context));
    }
    return result;

}
 
Example #4
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 6 votes vote down vote up
public static void unregister(Context context) {
    if (context == null)
        return;
    if (RomUtil.rom() == PhoneTarget.EMUI) {
        HWReceiver.clearPushListener();
        com.huawei.android.pushagent.api.PushManager.deregisterToken(context, getToken(context).getToken());
        return;

    }
    if (RomUtil.rom() == PhoneTarget.MIUI) {
        MiMessageReceiver.clearPushListener();
        MiPushClient.unregisterPush(context);
        return;
    }

    if (RomUtil.rom() == PhoneTarget.JPUSH) {
        JPushReceiver.clearPushListener();
        JPushInterface.stopPush(context);
        return;
    }
}
 
Example #5
Source File: PushConfig.java    From FastAndroid with Apache License 2.0 6 votes vote down vote up
public static void init(@NonNull Context context) {

        if ("HuaWei".equals(android.os.Build.MANUFACTURER)) {
            HMSAgent.init(context);
            HMSAgent.connect(this, new ConnectHandler() {
                @Override
                public void onConnect(int rst) {

                }
            });
            HMSAgent.Push.getToken(new GetTokenHandler() {
                @Override
                public void onResult(int rtnCode) {

                }
            });
        } else if ("Xiaomi".equals(android.os.Build.MANUFACTURER)) {
            MiPushClient.registerPush(context, "APP_ID", "APP_KEY");
        } else if (MzSystemUtils.isBrandMeizu(context)) {
            PushManager.register(context, "APP_ID", "APP_KEY");
        }else {

        }
    }
 
Example #6
Source File: MiPushReceiver.java    From GcmForMojo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
    Log.v(MYTAG,
            "onReceiveRegisterResult is called. " + message.toString());
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String log;
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            deviceMiToken = cmdArg1;
            Log.v(MYTAG,
                    "小米推送token:" + deviceMiToken);
        } else {
            Log.v(MYTAG,
                    "小米推送注册失败!" );
        }
    } else {
        log = message.getReason();
    }

}
 
Example #7
Source File: MiuiPushManager.java    From AndroidPush with Apache License 2.0 5 votes vote down vote up
@Override
public TokenModel getToken(Context context) {
    if (context == null)
        return null;
    TokenModel result = new TokenModel();
    result.setTarget(RomUtil.rom());
    result.setToken(MiPushClient.getRegId(context));
    return result;
}
 
Example #8
Source File: AVMiPushMessageReceiver.java    From java-unified-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommandResult(Context context, com.xiaomi.mipush.sdk.MiPushCommandMessage message) {
  super.onCommandResult(context, message);
  String command = message.getCommand();
  List<String> arguments = message.getCommandArguments();
  String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
  String cmdArg2 = (arguments != null && arguments.size() > 1) ? arguments.get(1) : null;
  if (MiPushClient.COMMAND_REGISTER.equals(command)) {
    if (message.getResultCode() == ErrorCode.SUCCESS) {
      updateAVInstallation(cmdArg1);
    }
  } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
    ;
  } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
    ;
  } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
    ;
  } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
    ;
  } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
    ;
  } else {
    ;
  }
}
 
Example #9
Source File: PushManager.java    From SimpleProject with MIT License 5 votes vote down vote up
public void initPush(Context context, String appId, String appKey, PushListener listener) {
	if (RomUtil.isMiui()) {
		MiPushClient.registerPush(context.getApplicationContext(), appId, appKey);
	} else if (RomUtil.isEmui()) {
		initHWPush(context.getApplicationContext());
	} else {
		JPushInterface.init(context.getApplicationContext());
	}
	mListener = listener;
}
 
Example #10
Source File: MiPushMsgReceiver.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
        }
    }
}
 
Example #11
Source File: XiaoMiPushMessageReceiver.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    Log.e("XiaoMiPushMessageReceiver","cmdArg1:"+cmdArg1+",cmdArg2:"+cmdArg2);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
        }
    }
}
 
Example #12
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 #13
Source File: XiaomiPushReceiver.java    From talk-android with MIT License 5 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage miPushCommandMessage) {
    Logger.d(TAG, "command result");
    String command = miPushCommandMessage.getCommand();
    List<String> arguments = miPushCommandMessage.getCommandArguments();
    final String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);

    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (miPushCommandMessage.getResultCode() == ErrorCode.SUCCESS && BizLogic.isLogin()) {
            if (StringUtil.isBlank(MainApp.PREF_UTIL.getString(Constant.XIAOMI_TOKEN))) {
                MainApp.PREF_UTIL.putString(Constant.XIAOMI_TOKEN, cmdArg1);
            }
            TalkClient.getInstance().getTalkApi()
                    .postToken(cmdArg1)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Action1<Object>() {
                        @Override
                        public void call(Object o) {
                            MainApp.PREF_UTIL.putString(Constant.XIAOMI_TOKEN, cmdArg1);
                            Logger.d(TAG, "xiaomi push register success: " + cmdArg1);
                        }
                    }, new Action1<Throwable>() {
                        @Override
                        public void call(Throwable throwable) {
                            Logger.e(TAG, "xiaomi push  register", throwable);
                        }
                    });
        }
    }
}
 
Example #14
Source File: WXMessageReceiver.java    From HightCopyWX with Apache License 2.0 5 votes vote down vote up
/**
 * 接收客户端向服务器发送命令消息后返回的响应
 *
 * @param context
 * @param message
 */
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
        }
    }
}
 
Example #15
Source File: WXMessageReceiver.java    From HightCopyWX with Apache License 2.0 5 votes vote down vote up
/**
     * 接受客户端向服务器发送注册命令消息后返回的响应
     *
     * @param context
     * @param message
     */
    @Override
    public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
        String command = message.getCommand();
        List<String> arguments = message.getCommandArguments();
        String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
        String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
        if (MiPushClient.COMMAND_REGISTER.equals(command)) {
            if (message.getResultCode() == ErrorCode.SUCCESS) {
                mRegId = cmdArg1;
            }
        }
//        Log.d("TAG", "register:" + mRegId);
        SPUtils.putString("regId", mRegId).commit();
    }
 
Example #16
Source File: MiPushMsgReceiver.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
        }
    }
}
 
Example #17
Source File: MiuiPushManager.java    From AndroidPush with Apache License 2.0 5 votes vote down vote up
@Override
public void resume(Context context) {
    MiPushClient.resumePush(context, null);
    if (MiuiReceiver.getPushInterface() != null) {
        MiuiReceiver.getPushInterface().onResume(context);
    }
}
 
Example #18
Source File: MiMessageReceiver.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
/**
 * 获取给服务器发送注册命令的结果,结果封装在MiPushCommandMessage类中
 */
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
        }
    }
}
 
Example #19
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 #20
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
/**
 * 停止推送
 */
public static void pause(Context context) {
    if (context == null)
        return;
    if (RomUtil.rom() == PhoneTarget.EMUI) {
        com.huawei.android.pushagent.api.PushManager.enableReceiveNormalMsg(context, false);
        com.huawei.android.pushagent.api.PushManager.enableReceiveNotifyMsg(context, false);
        if (HWReceiver.getPushListener() != null) {
            HWReceiver.getPushListener().onPaused(context);
        }
        return;

    }
    if (RomUtil.rom() == PhoneTarget.MIUI) {
        MiPushClient.pausePush(context, null);
        if (MiMessageReceiver.getPushListener() != null) {
            MiMessageReceiver.getPushListener().onPaused(context);
        }
        return;
    }

    if (RomUtil.rom() == PhoneTarget.JPUSH) {
        if (!JPushInterface.isPushStopped(context)) {
            JPushInterface.stopPush(context);
            if (JPushReceiver.getPushListener() != null) {
                JPushReceiver.getPushListener().onPaused(context);
            }
        }
    }

}
 
Example #21
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
/**
 * 开始推送
 */
public static void resume(Context context) {
    if (context == null)
        return;
    if (RomUtil.rom() == PhoneTarget.EMUI) {
        com.huawei.android.pushagent.api.PushManager.enableReceiveNormalMsg(context, true);
        com.huawei.android.pushagent.api.PushManager.enableReceiveNotifyMsg(context, true);
        if (HWReceiver.getPushListener() != null) {
            HWReceiver.getPushListener().onResume(context);
        }
        return;
    }
    if (RomUtil.rom() == PhoneTarget.MIUI) {
        MiPushClient.resumePush(context, null);
        if (MiMessageReceiver.getPushListener() != null) {
            MiMessageReceiver.getPushListener().onResume(context);
        }
        return;
    }

    if (RomUtil.rom() == PhoneTarget.JPUSH) {
        if (JPushInterface.isPushStopped(context)) {
            JPushInterface.resumePush(context);
            if (JPushReceiver.getPushListener() != null) {
                JPushReceiver.getPushListener().onResume(context);
            }
        }
    }
}
 
Example #22
Source File: MessageReceiver.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCommandResult(Context arg0, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            MyApplication.Push_Reg_ID = cmdArg1;
        } else {
            MyApplication.Push_Reg_ID = "";
        }
    } else {
        MyApplication.Push_Reg_ID = "";
    }
}
 
Example #23
Source File: MyApplication.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // 注册push服务,注册成功后会向DemoMessageReceiver发送广播
    // 可以从DemoMessageReceiver的onCommandResult方法中MiPushCommandMessage对象参数中获取注册信息
    if (shouldInit()) {
        MiPushClient.registerPush(this, APP_ID, APP_KEY);
    }

    // LoggerInterface newLogger = new LoggerInterface() {
    //
    // @Override
    // public void setTag(String tag) {
    // // ignore
    // }
    //
    // @Override
    // public void log(String content, Throwable t) {
    // Log.d(TAG, content, t);
    // }
    //
    // @Override
    // public void log(String content) {
    // Log.d(TAG, content);
    // }
    // };
    // Logger.setLogger(this, newLogger);
}
 
Example #24
Source File: ThirdPushManager.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void unsetAlias(Context context, String alias) {
    List<String> allAlias = MiPushClient.getAllAlias(context);
    for (int i = 0; i < allAlias.size(); i++) {
        MiPushClient.unsetAlias(context, allAlias.get(i), null);
    }
}
 
Example #25
Source File: XiaoMiPushMessageReceiver.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            AnalysysAgent.setPushID(context, PushProvider.XIAOMI, cmdArg1);
        }
    }
}
 
Example #26
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 #27
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 #28
Source File: ThirdPushMessageReceiver.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
        Logger.i(TAG + "onCommandResult => " + message.toString());
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
            QPushClient.setAlias(context, PhoneInfoUtils.getUniqueID());
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
        }
    }
}
 
Example #29
Source File: ThirdPushManager.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void unRegisterPush(Context context) {
    Logger.i("注销Third推送 unRegisterPush  appId : " + appId + "  appKey : " + appKey + "  regid : " + MiPushClient.getRegId(context));
    unsetAlias(context, null);
    MiPushClient.unregisterPush(context.getApplicationContext());
    HttpUtil.unregistPushinfo(PhoneInfoUtils.getUniqueID(), QTPushConfiguration.getPlatName(), true);
}
 
Example #30
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);
    }