2017-01-02 56 views
-1

在我的Android应用程序中,需要知道是否有一些dataActivity或不... 我知道有一个名为TelephonyManager.DATA_ACTIVITY_NONE的枚举。如何获取当前设备数据活动Android

我怎样才能得到这个值?

(作为奖励功能;))有一些方法来获得当前的下载/上传速度?

这里我的代码:

public static int getDeviceNetwokActivity(Context context){ 
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 

    return tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE 
        | PhoneStateListener.LISTEN_DATA_ACTIVITY); 
} 

非常感谢!

+0

我有root权限! – r1si

回答

0

我发现这个代码的解决方案:

/** 
* Function that get the current device netwok activity 
* @param Context context - The context of application 
* @return int - [0,1,2,3,4,5,6] 
*/ 
public static int getDeviceNetwokActivity(Context context){ 
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); // TelehponyManager 
    return manager.getDataActivity(); 
} 
相关问题