Java Code Examples for cn.jpush.android.api.JPushInterface#setAlias()

The following examples show how to use cn.jpush.android.api.JPushInterface#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: ContactFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
private void handleAutoLogin(Message msg){
    String result = msg.obj.toString();
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot  root = gson.fromJson(result, LoginRoot.class);

    if (root == null){
        Toast.makeText(getActivity(), "服务器繁忙,请重试", Toast.LENGTH_LONG).show();
        return;
    }

    if (root.seccess){
        getFriendList();
    }

    //登录成功后为每个用户设置别名:username
    JPushInterface.setAlias(getActivity(), root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });

}
 
Example 2
Source File: ModifyUserDataActivity.java    From Social with Apache License 2.0 6 votes vote down vote up
private void handleAutoLogin(Message msg){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("已自动登录");
    builder.setContentText("请重新操作...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    String result = msg.obj.toString();
    Log.d("Setting", result);
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot root = gson.fromJson(result, LoginRoot.class);
    JPushInterface.setAlias(this, root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });

}
 
Example 3
Source File: UserDataDetailActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void handleAutoLogin(Message msg){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("已自动登录");
    builder.setContentText("请重新操作...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    //发广播通知MainActivity修改界面
    Intent intent = new Intent("com.allever.autologin");
    sendBroadcast(intent);

    String result = msg.obj.toString();
    Log.d("Setting", result);
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot root = gson.fromJson(result, LoginRoot.class);
    JPushInterface.setAlias(this, root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });


}
 
Example 4
Source File: GosPushManager.java    From gokit-android with MIT License 5 votes vote down vote up
/**
 * 向云端绑定推送
 * 
 * @param Token
 * @param Channel_ID
 * @param gizPushType
 */
public static void pushBindService(String token) {

	if (GizPushType.GizPushJiGuang == gizPushType) {
		// 获取JPush的RegistrationID,即Channel_ID
		Channel_ID = JPushInterface.getRegistrationID(context);

		// 设定JPush类型
		JPushInterface.setAlias(context, Channel_ID, new TagAliasCallback() {
			@Override
			public void gotResult(int arg0, String arg1, Set<String> arg2) {
				if (arg0 == 0) {
					Log.i("Apptest", "Alias: " + arg1);
				} else {
					Log.e("Apptest", "Result: " + arg0);
				}
			}
		});

	} else if (GizPushType.GizPushBaiDu == gizPushType) {
		// 获取BDPush的Channel_ID
		Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
	} else {
		return;
	}

	// TODO 绑定推送
	Log.i("Apptest", Channel_ID + "\n" + gizPushType.toString() + "\n" + token);
	GizWifiSDK.sharedInstance().channelIDBind(token, Channel_ID, gizPushType);
}
 
Example 5
Source File: GosPushManager.java    From Gizwits-SmartBuld_Android with MIT License 5 votes vote down vote up
/**
 * 向云端绑定推送
 * 
 * @param Token
 * @param Channel_ID
 * @param gizPushType
 */
public static void pushBindService(String token) {

	if (GizPushType.GizPushJiGuang == gizPushType) {
		// 获取JPush的RegistrationID,即Channel_ID
		Channel_ID = JPushInterface.getRegistrationID(context);

		// 设定JPush类型
		JPushInterface.setAlias(context, Channel_ID, new TagAliasCallback() {
			@Override
			public void gotResult(int arg0, String arg1, Set<String> arg2) {
				if (arg0 == 0) {
					Log.i("Apptest", "Alias: " + arg1);
				} else {
					Log.e("Apptest", "Result: " + arg0);
				}
			}
		});

	} else if (GizPushType.GizPushBaiDu == gizPushType) {
		// 获取BDPush的Channel_ID
		Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
	} else {
		return;
	}

	// TODO 绑定推送
	Log.i("Apptest", Channel_ID + "\n" + gizPushType.toString() + "\n" + token);
	GizWifiSDK.sharedInstance().channelIDBind(token, Channel_ID, gizPushType);
}
 
Example 6
Source File: GosPushManager.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
/**
 * 向云端绑定推送
 * 
 * @param Token
 * @param Channel_ID
 * @param gizPushType
 */
public static void pushBindService(String token) {

	if (GizPushType.GizPushJiGuang == gizPushType) {
		// 获取JPush的RegistrationID,即Channel_ID
		Channel_ID = JPushInterface.getRegistrationID(context);

		// 设定JPush类型
		JPushInterface.setAlias(context, Channel_ID, new TagAliasCallback() {
			@Override
			public void gotResult(int arg0, String arg1, Set<String> arg2) {
				if (arg0 == 0) {
					Log.i("Apptest", "Alias: " + arg1);
				} else {
					Log.e("Apptest", "Result: " + arg0);
				}
			}
		});

	} else if (GizPushType.GizPushBaiDu == gizPushType) {
		// 获取BDPush的Channel_ID
		Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
	} else {
		return;
	}

	// TODO 绑定推送
	Log.i("Apptest", Channel_ID + "\n" + gizPushType.toString() + "\n" + token);
	GizWifiSDK.sharedInstance().channelIDBind(token, Channel_ID, gizPushType);
}
 
Example 7
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 8
Source File: JPushManager.java    From AndroidPush with Apache License 2.0 5 votes vote down vote up
@Override
public void setAlias(final Context context, String alias) {
    JPushInterface.setAlias(context, alias, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {
            if (i == 0) { // 这里极光规定0代表成功
                if (JPushReceiver.getPushInterface() != null) {
                    L.i("JPushInterface.setAlias");
                    JPushReceiver.getPushInterface().onAlias(context, s);

                }
            }
        }
    });
}
 
Example 9
Source File: NewsDetailActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void handleAutoLogin(Message msg){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("已自动登录");
    builder.setContentText("请重新操作...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    //发广播通知MainActivity修改界面
    Intent intent = new Intent("com.allever.autologin");
    sendBroadcast(intent);

    String result = msg.obj.toString();
    Log.d("Setting", result);
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot root = gson.fromJson(result, LoginRoot.class);
    JPushInterface.setAlias(this, root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });


}
 
Example 10
Source File: UserDataActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void handleAutoLogin(Message msg){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("已自动登录");
    builder.setContentText("请重新操作...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    //发广播通知MainActivity修改界面
    Intent intent = new Intent("com.allever.autologin");
    sendBroadcast(intent);

    String result = msg.obj.toString();
    Log.d("Setting", result);
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot root = gson.fromJson(result, LoginRoot.class);
    JPushInterface.setAlias(this, root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });


}
 
Example 11
Source File: LongConnectionService.java    From Social with Apache License 2.0 5 votes vote down vote up
private void handleAutoLogin(NetResponse netResponse){
    Log.d(TAG, "handleAutoLogin: ");
    String result = netResponse.getString();
    Log.d(TAG, "handleAutoLogin: result = " + result);

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    Type type = new TypeToken<Response<com.allever.social.bean.User>>() {}.getType();
    com.allever.social.bean.Response<com.allever.social.bean.User> root = gson.fromJson(result,type);

    if (root.isSuccess()){
        Log.d(TAG, "handleAutoLogin: autoLogin success");
        SharedPreferenceUtil.setSessionId(root.getSession_id());
        Log.d(TAG, "handleAutoLogin: set session_id = " + root.getSession_id());
        SharedPreferenceUtil.setState("1");
    }else {
        Log.d(TAG, "handleAutoLogin: autoLogin fail");
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("Social");
    builder.setContentText("已重新登录...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    //登录成功后为每个用户设置别名:username
    JPushInterface.setAlias(this, root.getData().getUsername(), new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });
}
 
Example 12
Source File: HostMonitor.java    From Social with Apache License 2.0 5 votes vote down vote up
private void loginHuanxinAndJpush(){
    //登录环信
    //登录app服务器成功后登录环信服务器
    EMClient.getInstance().login(SharedPreferenceUtil.getUserName(), SharedPreferenceUtil.getPassword(), new EMCallBack() {//回调
        @Override
        public void onSuccess() {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    EMClient.getInstance().groupManager().loadAllGroups();
                    EMClient.getInstance().chatManager().loadAllConversations();
                    Log.d(TAG, "登陆聊天服务器成功!");
                }
            }).start();

        }

        @Override
        public void onProgress(int progress, String status) {

        }

        @Override
        public void onError(int code, String message) {
            Log.d(TAG, "登陆聊天服务器失败!\n" + message);
        }
    });


    JPushInterface.setAlias(this, SharedPreferenceUtil.getUserName(), new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });
}
 
Example 13
Source File: InitJPushTask.java    From android-performance with MIT License 4 votes vote down vote up
@Override
public void run() {
    JPushInterface.init(mContext);
    PerformanceApp app = (PerformanceApp) mContext;
    JPushInterface.setAlias(mContext, 0, app.getDeviceId());
}
 
Example 14
Source File: TagAliasOperatorHelper.java    From iMoney with Apache License 2.0 4 votes vote down vote up
/**
 * 处理设置tag
 */
public void handleAction(Context context, int sequence, TagAliasBean tagAliasBean) {
    init(context);
    if (tagAliasBean == null) {
        LogUtil.e(TAG, "tagAliasBean was null");
        return;
    }
    put(sequence, tagAliasBean);
    if (tagAliasBean.isAliasAction) {
        switch (tagAliasBean.action) {
            case ACTION_GET:
                JPushInterface.getAlias(context, sequence);
                break;
            case ACTION_DELETE:
                JPushInterface.deleteAlias(context, sequence);
                break;
            case ACTION_SET:
                JPushInterface.setAlias(context, sequence, tagAliasBean.alias);
                break;
            default:
                LogUtil.e(TAG, "unSupport alias action type");
                break;
        }
    } else {
        switch (tagAliasBean.action) {
            case ACTION_ADD:
                JPushInterface.addTags(context, sequence, tagAliasBean.tags);
                break;
            case ACTION_SET:
                JPushInterface.setTags(context, sequence, tagAliasBean.tags);
                break;
            case ACTION_DELETE:
                JPushInterface.deleteTags(context, sequence, tagAliasBean.tags);
                break;
            case ACTION_CHECK:
                // 一次只能 check 一个 tag
                String tag = (String) tagAliasBean.tags.toArray()[0];
                JPushInterface.checkTagBindState(context, sequence, tag);
                break;
            case ACTION_GET:
                JPushInterface.getAllTags(context, sequence);
                break;
            case ACTION_CLEAN:
                JPushInterface.cleanTags(context, sequence);
                break;
            default:
                LogUtil.e(TAG, "unSupport tag action type");
                break;
        }
    }
}
 
Example 15
Source File: LoginPresenter.java    From Social with Apache License 2.0 4 votes vote down vote up
private void handleLogin(Context context, String result, String pwd) {
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    Type type = new TypeToken<Response<User>>() {}.getType();
    Response<User> root = gson.fromJson(result,type);

    if (root == null){
        mViewRef.get().showErrorMessageToast(root.getMessage());
        return;
    }

    if (!root.isSuccess()){
        mViewRef.get().showTipsDialog(root.getMessage());
        return ;
    }

    mViewRef.get().loginSuccess();

    //登录成功后为每个用户设置别名:username
    User user = root.getData();
    JPushInterface.setAlias(context, root.getData().getUsername(), new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {
            Log.d("JPush", i + "");
        }
    });

    //登录app服务器成功后登录环信服务器
    EMClient.getInstance().login(user.getUsername(), pwd, new EMCallBack() {//回调
        @Override
        public void onSuccess() {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    EMClient.getInstance().groupManager().loadAllGroups();
                    EMClient.getInstance().chatManager().loadAllConversations();
                    Log.d("LoninFragment", "登陆聊天服务器成功!");
                }
            }).start();

        }

        @Override
        public void onProgress(int progress, String status) {

        }

        @Override
        public void onError(int code, String message) {
            Log.d("LoninFragment", "登陆聊天服务器失败!");
        }
    });

    SharedPreferenceUtil.setUserId(user.getId());
    SharedPreferenceUtil.setUsername(user.getUsername());
    SharedPreferenceUtil.setNickname(user.getNickname());
    SharedPreferenceUtil.setPassword(pwd);
    SharedPreferenceUtil.setHeadpath(user.getUser_head_path());
    SharedPreferenceUtil.setSignature(user.getSignature());
    SharedPreferenceUtil.setState("1");
    SharedPreferenceUtil.setSessionId(root.getSession_id());
    SharedPreferenceUtil.setCity(user.getCity());
    SharedPreferenceUtil.setSex(user.getSex());
    SharedPreferenceUtil.setPhone(user.getPhone());
    SharedPreferenceUtil.setEmail(user.getEmail());
    SharedPreferenceUtil.setAge(user.getAge());
    SharedPreferenceUtil.setOccupation(user.getOccupation());
    SharedPreferenceUtil.setConstellation(user.getConstellation());
    SharedPreferenceUtil.setHihgt(user.getHight());
    SharedPreferenceUtil.setWeight(user.getWeight());
    SharedPreferenceUtil.setFigure(user.getFigure());
    SharedPreferenceUtil.setEmotion(user.getEmotion());
    SharedPreferenceUtil.setVip(user.getIs_vip() + "");
    SharedPreferenceUtil.setRecommend(user.getIs_recommended() + "");
    SharedPreferenceUtil.setAutoReaction(user.getAutoreaction());
    SharedPreferenceUtil.setOnlineState(user.getOnlinestate());
    SharedPreferenceUtil.setOpenid(user.getQq_open_id());
}
 
Example 16
Source File: InitHelper.java    From AndroidAll with Apache License 2.0 4 votes vote down vote up
public static void initJPush(Context context) {
    JPushInterface.init(context.getApplicationContext());
    JPushInterface.setAlias(context.getApplicationContext(), 0, "deviceidxxxx000xxx");
}
 
Example 17
Source File: PushActivity.java    From AndroidFrame with Apache License 2.0 4 votes vote down vote up
public void setAlias(View view) {
    JPushInterface.setAlias(LQBApp.getApp(), 1000, "woshi007");
    Toast.makeText(this, "别名已设置", Toast.LENGTH_SHORT).show();
}
 
Example 18
Source File: PerformanceApp.java    From android-performance with MIT License 4 votes vote down vote up
private void initJPush() {
    JPushInterface.init(this);
    JPushInterface.setAlias(this, 0, mDeviceId);
}