package com.jiuqi.njt.util.login; import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.ExecutionException; import com.jiuqi.mobile.nigo.comeclose.exception.LoginException; import com.jiuqi.njt.data.MyApp; import com.jqyd.android.module.lbs.util.CheckState_interface; import android.content.Context; import android.widget.Toast; /** * 客户端获取新Session工具类 * 当出现Session 超时时可通过该工具类重新获取新的Session */ public class AutoLoginUtil { private MyApp application; private boolean isLoginSuccess; private Context context; private Exception exception; public AutoLoginUtil(Context context, Exception exception) { super(); this.context = context; this.application = (MyApp) context.getApplicationContext(); this.exception = exception; } //判断异常的类型和内容是不是Session超时,如果是就调用方法重新获取 public boolean getNewSession() { if (new CheckState_interface(context).checkConnection()) { try { if (null!=exception&&exception instanceof LoginException||exception instanceof UndeclaredThrowableException&& exception.getMessage().contains("您的登录信息已过期,请重新登录!")) { try { isLoginSuccess = new AutoLoginTask(context).execute().get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast.makeText(context, "没有网络连接", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { e.printStackTrace(); } } return isLoginSuccess; } }