cn.jpush.android.api.TagAliasCallback Java Examples

The following examples show how to use cn.jpush.android.api.TagAliasCallback. 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: 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 #4
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 #5
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 #6
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 #7
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 #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: 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 #10
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 #11
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 #12
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 #13
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 #14
Source File: PushManager.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
/**
     * 设置标签
     *
     * @param context
     * @param tag
     */
    public static void setTag(final Context context, String tag) {
//        if (TextUtils.isEmpty(tag))
//            return;
        if (RomUtil.rom() == PhoneTarget.EMUI) {
            Map<String, String> tagMap = new HashMap<>();
            tagMap.put("tag", tag);
            com.huawei.android.pushagent.api.PushManager.setTags(context, tagMap);
            return;

        }
        if (RomUtil.rom() == PhoneTarget.MIUI) {
            MiPushClient.subscribe(context, tag, null);
            return;
        }

        if (RomUtil.rom() == PhoneTarget.JPUSH) {

            Set<String> tagSet = new LinkedHashSet<>();
            if (!TextUtils.isEmpty(tag)) {
                String[] sArray = tag.split(",");
                for (String sTagItme : sArray) {
//                    if (!JPushUtils.isValidTagAndAlias(sTagItme)) {
//                        continue;
//                    }
                    tagSet.add(sTagItme);
                }
            }
            JPushInterface.setTags(context, tagSet, new TagAliasCallback() {
                @Override
                public void gotResult(int i, final String s, final Set<String> set) {
                    String logs;
                    switch (i) {
                        case 0:
                            logs = "Set tag and alias success";
                            break;
//                        case 6002:
//                            logs = "Failed to set alias and tags due to timeout. Try again after 60s.";
//                            KLog.d(logs);
//                            if (JPushUtils.isConnected(context)) {
//                                Observable.empty().delay(1, TimeUnit.MINUTES).subscribe(new Action1<Object>() {
//                                    @Override
//                                    public void call(Object o) {
//
//                                        if (s != null) {
//                                            setAlias(context, s);
//                                        }
//                                        if (set != null) {
//                                            JPushInterface.setTags(context, set, this);
//                                        }
//
//                                    }
//                                });
//                            } else {
//                                KLog.d("No network");
//                            }
//                            break;
//                        default:
//                            logs = "Failed with errorCode = " + i;
//                            KLog.e("qcxy", logs);
                    }
                }
            });
        }

    }