Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry® World™ Development

Reply
New Contributor
Posts: 8
Registered: ‎08-24-2012
My Device: 8520
Accepted Solution

WLANConnectionListener and RadioStatusListener not listening the radio On and Off information

Here in my case  when I was in my application I am able to get the information about the radio wifi on and off . But when when I cosed the application(Or I am out off my application) then its doesn't not listen the information regarding to on and off of wifi.

 

What I actually trying is that, I want to fetch the amount of data send and received over 3G network. No direct api is available . Therefore I think to get the information of wifi on and off status. when wifi is on no data recorded in database but when the wifi stops then I want to store data in my DB.

 

Please help if I am doing something wrong

 

Below is my code.

 

/*
* Calling method from another class
*/
MobileDataListener mobileDataListenerOBJ=new MobileDataListener();
mobileDataListenerOBJ.listenerREMOVED();
mobileDataListenerOBJ.listenerSTARTER();

 

 

 

/*

*        Main class

**/
import net.rim.device.api.system.Application;
import net.rim.device.api.system.RadioInfo;
import net.rim.device.api.system.RadioStatusListener;
import net.rim.device.api.system.WLANConnectionListener;
import net.rim.device.api.system.WLANInfo;
import net.rim.device.api.system.WLANListener;
import com.main.Main;

public class MobileDataListener implements WLANListener, WLANConnectionListener, RadioStatusListener
{
Main main;
public MobileDataListener()
{
System.out.println(":::::::::::INSIDE MOBILEDATALISTENER::::::::::::::::::");
}

public void listenerSTARTER()
{
Application.getApplication().addRadioListener(RadioInfo.WAF_WLAN, this);
WLANInfo.addListener(this);
}
public void listenerREMOVED()
{
try
{
Application.getApplication().removeRadioListener(this);
WLANInfo.removeListener(this);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void baseStationChange() {}
public void networkScanComplete(boolean success) {}
public void networkServiceChange(int networkId, int service) {}
public void networkStarted(int networkId, int service) {}
public void networkStateChange(int state) {}
public void pdpStateChange(int apn, int state, int cause) {}
public void radioTurnedOff()
{
System.out.println("W O R KI N G :::::::::::::::::::RADIO TURNED OFF:::::::::::::::7");
}
public void signalLevel(int level) {System.out.println("::::::::smileyfrustrated:ignal Level::::::::::"+level);}

public void networkConnected()
{
System.out.println("<<<<<<<<<<<<<<<<<WIFI NETWORK Connected>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
DataConsumptionThread dataThreadObj=new DataConsumptionThread(false, this);
dataThreadObj.start();
}


public void networkDisconnected(int arg0)
{
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<WLAN network disconnected>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
DataConsumptionThread dataThreadObj=new DataConsumptionThread(true, this);
dataThreadObj.start();

switch (arg0) {
case WLAN_ASSOCIATION_FAILED:
break;
case WLAN_AUTH_FAIL:
break;
case WLAN_CONNECTION_TERMINATED:
break;
case WLAN_DHCP_UNREACHABLE:
break;
case WLAN_IP_ADDRESS_LOST:
break;
case WLAN_OUT_OF_COVERAGE:
break;
case WLAN_UNSPECIFIED_REASON:
break;
}
}
}
class DataConsumptionThread extends Thread
{
MobileDataListener mobileDataListenerObj;
long _currentConsuption_send;
long _currentConsuption_recv;
boolean _state=false;

long lastConsuption_send;
long lastConsuption_rec;

long totalConsuption_send;
long totalConsuption_recv;

long finalData_rec=0;
long finalData_send=0;
long lastTimeAttempt;


DataConsumptionThread(boolean state,MobileDataListener application)
{
_state=state;
}

public void run()
{
while(_state)
{
System.out.println("::::::::::::::::C A L C U L A T O T O R S T A R T S::::::::::::::::::::");
try
{
_currentConsuption_send=RadioInfo.getNumberOfPacketsSent();
_currentConsuption_recv=RadioInfo.getNumberOfPacketsReceived();
System.out.println(":::::::::Current Data send:::::::::"+_currentConsuption_send);
System.out.println(":::::::::Current Data recv:::::::::"+_currentConsuption_recv);

if(_currentConsuption_recv != lastConsuption_rec)
{
totalConsuption_recv=_currentConsuption_recv - lastConsuption_rec ;

finalData_rec += totalConsuption_recv; 

lastConsuption_rec = _currentConsuption_recv;

}

if(_currentConsuption_send != lastConsuption_send)
{
totalConsuption_send =_currentConsuption_send - lastConsuption_send;

finalData_send += totalConsuption_send;

lastConsuption_send = _currentConsuption_send;
}
double byteUsed=totalConsuption_recv+totalConsuption_send;
System.out.println("ORIGINAL BYTE CONSIUMED"+byteUsed+" Mb");
Thread.sleep(15*1000);

}
catch(Exception e)
{
System.out.println(e.toString());
}

}

}

}

 

 

Thanks in advance.....:smileyhappy:

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: WLANConnectionListener and RadioStatusListener not listening the radio On and Off information

This forum section is for using the NDK for BB10/Playbook, which is C/C++, not JAVA. For the JAVA development you should be posting in http://supportforums.blackberry.com/t5/Java-Development/bd-p/java_dev

New Contributor
Posts: 8
Registered: ‎08-24-2012
My Device: 8520

Re: WLANConnectionListener and RadioStatusListener not listening the radio On and Off information

Thanks mreed