Java Code Examples for com.xiaomi.mipush.sdk.MiPushCommandMessage#getReason()

The following examples show how to use com.xiaomi.mipush.sdk.MiPushCommandMessage#getReason() . 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: 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 2
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 3
Source File: DemoMessageReceiver.java    From star-zone-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
    Log.v(MyApp.TAG,
            "onCommandResult 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 cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    String log;
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
            Log.i(MyApp.TAG, "OnRegisterSuccess_mRegId=" + mRegId);
            MyApp.getInstance().setAlias();
            log = context.getString(R.string.register_success);
            SharedPreferencesMyUtil.storeMiRegid(MyApp.getInstance(), mRegId);
            String storedRegid = SharedPreferencesMyUtil.queryMiRegid(MyApp.getInstance());
            Log.i(MyApp.TAG, "storedRegid=" + storedRegid);
        } else {
            log = context.getString(R.string.register_fail);
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
            log = context.getString(R.string.set_alias_success, mAlias);
            Log.i(MY_TAG, "---onCommandResult_setAlias,alias=" + mAlias);
        } else {
            log = context.getString(R.string.set_alias_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
            log = context.getString(R.string.unset_alias_success, mAlias);
        } else {
            log = context.getString(R.string.unset_alias_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SET_ACCOUNT.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAccount = cmdArg1;
            log = context.getString(R.string.set_account_success, mAccount);
        } else {
            log = context.getString(R.string.set_account_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSET_ACCOUNT.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAccount = cmdArg1;
            log = context.getString(R.string.unset_account_success, mAccount);
        } else {
            log = context.getString(R.string.unset_account_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
            log = context.getString(R.string.subscribe_topic_success, mTopic);
        } else {
            log = context.getString(R.string.subscribe_topic_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
            log = context.getString(R.string.unsubscribe_topic_success, mTopic);
        } else {
            log = context.getString(R.string.unsubscribe_topic_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
            log = context.getString(R.string.set_accept_time_success, mStartTime, mEndTime);
        } else {
            log = context.getString(R.string.set_accept_time_fail, message.getReason());
        }
    } else {
        log = message.getReason();
    }
    ChatWindowActivity.logList.add(0, getSimpleDate() + "    " + log);

    Message msg = Message.obtain();
    msg.obj = log;
    MyApp.getHandler().sendMessage(msg);
}