如何防止github android客户端端同时登录

【Android反馈】能否禁止一个账号在两个手机上同时登陆。_贴吧客户端反馈吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
【Android反馈】能否禁止一个账号在两个手机上同时登陆。收藏
百度贴吧客户端6.2.1, 4.1.2, HUAWEI G730-C00, WIFI:
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或安卓优酷客户端怎么禁止自动播放下一集?烦死了!_百度知道Android客户端与服务端交互之登陆示例
今天了解了一下android客户端与服务端是怎样交互的,发现其实跟web有点类似吧,然后网上找了大神的登陆示例,是基于IntentService的
1.后台使用简单的servlet,支持GET或POST。这个servlet最终返回给前台一个字符串flag,值是true或false,表示登录是否成功。
servlet使用之前需要配置,主义servlet的servlet-name要和servlet-mapping的servlet-name一致,否则找不到路径
我是在myEclipse上创建的一个web service 项目,然后部署到tomcat服务器上以便android客户端访问
helloWorld
com.zhongzhong.wap.action.HelloServlet
helloWorld
/queryOrder
import java.io.IOE
import java.io.PrintW
import javax.servlet.ServletE
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpS
import com.zhongzhong.wap.bean.UserB
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType(text/html);
PrintWriter out = resp.getWriter();
Boolean flag =
String userName = req.getParameter(un);
String password = req.getParameter(pw);
if(userName.equals(htp)&&password.equals(123))
else flag =
System.out.println(userName:+userName+ password:+password);
out.print(flag);
out.flush();
out.close();
2.然后我是在安卓的ADT上创建一个安卓项目,建立两个Activity,分别作为登录界面和登录成功界面。
3.HTTP的访问公共类,用于处理GET和POST请求
package com.example.
import java.util.ArrayL
import java.util.L
import java.util.M
import org.apache.http.HttpR
import org.apache.http.NameValueP
import org.apache.http.client.HttpC
import org.apache.http.client.entity.UrlEncodedFormE
import org.apache.http.client.methods.HttpG
import org.apache.http.client.methods.HttpP
import org.apache.http.impl.client.DefaultHttpC
import org.apache.http.message.BasicNameValueP
import org.apache.http.util.EntityU
import android.content.E
import android.util.L
public class HttpUtil {
// 创建HttpClient对象
public static HttpClient httpClient = new DefaultHttpClient();
public static final String BASE_URL = http://192.168.3.14:8090/HelloWord/;
* @param url
发送请求的URL
* @return 服务器响应字符串
* @throws Exception
public static String getRequest(String url) throws Exception {
// 创建HttpGet对象。
HttpGet get = new HttpGet(url);
// 发送GET请求
HttpResponse httpResponse = httpClient.execute(get);
// 如果服务器成功地返回响应
if (httpResponse.getStatusLine().getStatusCode() == 200) {
// 获取服务器响应字符串
String result = EntityUtils.toString(httpResponse.getEntity());
Log.d(服务器响应代码, (new Integer(httpResponse.getStatusLine()
.getStatusCode())).toString());
* @param url
发送请求的URL
* @param params
* @return 服务器响应字符串
* @throws Exception
public static String postRequest(String url, Map rawParams)
throws Exception {
// 创建HttpPost对象。
HttpPost post = new HttpPost(url);
// 如果传递参数个数比较多的话可以对传递的参数进行封装
List params = new ArrayList();
for (String key : rawParams.keySet()) {
// 封装请求参数
params.add(new BasicNameValuePair(key, rawParams.get(key)));
// 设置请求参数
post.setEntity(new UrlEncodedFormEntity(params, UTF-8));
// 发送POST请求
HttpResponse httpResponse = httpClient.execute(post);
// 如果服务器成功地返回响应
if (httpResponse.getStatusLine().getStatusCode() == 200) {
// 获取服务器响应字符串
String result = EntityUtils.toString(httpResponse.getEntity());
4.IntentService服务,用于在后台以队列方式处理耗时操作。
package com.example.
import java.util.HashM
import android.app.IntentS
import android.content.I
import android.util.L
public class ConnectService extends IntentService {
private static final String ACTION_RECV_MSG = com.example.logindemo.action.RECEIVE_MESSAGE;
public ConnectService() {
super(TestIntentService);
// TODO Auto-generated constructor stub
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
* 经测试,IntentService里面是可以进行耗时的操作的
* IntentService使用队列的方式将请求的Intent加入队列,
* 然后开启一个worker thread(线程)来处理队列中的Intent
* 对于异步的startService请求,IntentService会处理完成一个之后再处理第二个
Boolean flag =
//通过intent获取主线程传来的用户名和密码字符串
String username = intent.getStringExtra(username);
String password = intent.getStringExtra(password);
flag = doLogin(username, password);
Log.d(登录结果, flag.toString());
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ACTION_RECV_MSG);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra(result, flag.toString());
sendBroadcast(broadcastIntent);
// 定义发送请求的方法
private Boolean doLogin(String username, String password)
String strFlag = ;
// 使用Map封装请求参数
HashMap map = new HashMap();
map.put(un, username);
map.put(pw, password);
// 定义发送请求的URL
String url = HttpUtil.BASE_URL + queryOrder?un= + username + &pw= +
// String url = HttpUtil.BASE_URL + LoginS //POST方式
Log.d(url, url);
Log.d(username, username);
Log.d(password, password);
// 发送请求
strFlag = HttpUtil.postRequest(url, map);
//POST方式
strFlag = HttpUtil.getRequest(url);
Log.d(服务器返回值, strFlag);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(strFlag.trim().equals(true)){
5。在AndroidManifest.xml中注册IntentService。注意uses-permission节点,为程序开启访问网络的权限。
6.登陆界面处理,注意
按钮监听事件中,使用Intent将要传递的值传给service。接收广播类中,同样使用Intent将要传递的值传给下一个Activity。在onCreate()中,动态注册接收广播类的实例receiver。在接收广播类中,不要使用完毕后忘记注销接收器,否则会报一个Are you missing a call to unregisterReceiver()? 的异常。
package com.example.
import android.os.B
import android.app.A
import android.content.BroadcastR
import android.content.C
import android.content.I
import android.content.IntentF
import android.util.L
import android.view.M
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.EditT
import android.widget.T
public class MainActivity extends Activity {
private static final String ACTION_RECV_MSG = com.example.logindemo.action.RECEIVE_MESSAGE;
private Button loginB
private EditText et_
private EditText et_
private String userN
private String passW
private MessageR
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
//动态注册receiver
IntentFilter filter = new IntentFilter(ACTION_RECV_MSG);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new MessageReceiver();
registerReceiver(receiver, filter);
private void initView() {
// TODO Auto-generated method stub
et_username = (EditText)findViewById(R.id.et_user);
et_password =( EditText)findViewById(R.id.et_psw);
loginBtn = (Button)findViewById(R.id.btn_login);
loginBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(matchLoginMsg())
// 如果校验成功
Intent msgIntent = new Intent(MainActivity.this, ConnectService.class);
msgIntent.putExtra(username, et_username.getText().toString().trim());
msgIntent.putExtra(password, et_password.getText().toString().trim());
startService(msgIntent);
protected boolean matchLoginMsg() {
// TODO Auto-generated method stub
userName = et_username.getText().toString().trim();
passWord = et_password.getText().toString().trim();
if(userName.equals())
Toast.makeText(MainActivity.this, 账号不能为空,Toast.LENGTH_SHORT).show();
if(passWord.equals())
Toast.makeText(MainActivity.this, 密码不能为空,Toast.LENGTH_SHORT).show();
//接收广播类
public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra(result);
Log.i(MessageReceiver, message);
// 如果登录成功
if (message.equals(true)){
// 启动Main Activity
Intent nextIntent = new Intent(MainActivity.this, NaviActivity.class);
startActivity(nextIntent);
// 结束该Activity
//注销广播接收器
context.unregisterReceiver(this);
Toast.makeText(MainActivity.this, 用户名或密码错误,请重新输入!,Toast.LENGTH_SHORT).show();
public boolean onCreateOptionsMenu(Menu menu) {
// I this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
运行截图:
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'关于客户端版本过低怎么解决_全民突击吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0可签7级以上的吧50个
本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:188,233贴子:
关于客户端版本过低怎么解决
客户端版本过低怎么解决 不然合作邀请都不行
研究了几分钟发现问题了...
图片来自吧友 @团灭新...
不是说这次更新完了之后...
早上应该很多人都遇到游...
按照步骤,完完全全告别...
比较简单,大概算【伪】...
该方法为瞎猫碰死耗子摸...
NO.1 游戏更新后自带的Q...
亲爱的召唤师: 在最近...
现在分区浏览正常了 欢...
放开那三国2重塑三国卡牌手游新篇章,现在登录名将4选一,元宝免费领!让你时刻玩转三国!首创剿匪玩法,体验指尖大暴走!游戏内全屏弹幕聊到爽,快来和众多三国玩家一起嗨翻三国!
卸载之后重新安装
升级啊,安卓的话应用宝可以更新的
安装过啦,就是不行
应用宝上没有显示
晚上十二点以后随机匹配,至少没有小学生
应用宝搜全民突击就可以更新了
应用宝里更新
贴吧热议榜
使用签名档&&
保存至快速回贴如何防止Android客户端同时登录?就是一个用户只能在一个手机上,不能多手机同时在线。_百度知道}

我要回帖

更多关于 android 防止重复登录 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信