android代码来检测我的android应用程序用户是否在线 [英] android code to detect whether my android app user is online or not

查看:91
本文介绍了android代码来检测我的android应用程序用户是否在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Android应用程序,并已在Google Play中启动了它.它已经被许多人下载(大约200-300).现在我的问题是我想知道我的用户是否在线.实际上,当用户在线时,我想在我的服务器中为该用户执行特定操作.我怎么知道用户在线并且正在查看我的应用程序屏幕?

I have developed a android application, have launched it in google play. It has been downloaded by many people (around 200-300) . Now my question is i want to know if my user is online or not. Actually i want to perform a particular action in my server for that user when the user is online. How can i know the user is online and currently viewing my app screen?

我尝试了以下代码,该代码只能说明设备是否具有互联网连接.

i have tried the below code , which can only say whether device has internet conncetion or not..

private boolean isOnline()
    {
        try
        {
            ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
            return cm.getActiveNetworkInfo().isConnectedOrConnecting(); 
        }
        catch (Exception e)
        {
            return false;
        }
    }

我如何知道我的用户现在是否正在查看我的应用程序屏幕?我希望会有一个可用的选择!

How can i know whether my user is viewing my app screen now? i hope there will be a option available for this!

推荐答案

尝试在 onResume onPause 方法中添加一些代码

Try to have some code in onResume and onPause methods

@Override
public void onResume() {
    super.onResume();
    isOnline(true);
    }
}


@Override
public void onPause() {
    super.onPause();
    isOnline(false);
}

这篇关于android代码来检测我的android应用程序用户是否在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆