BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-19-2011, 05:57 AM   #1
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Blackberry System Listener issues

Please Login to Remove!

hi,

I am working in app in which i have to push screen when device is charging . Now device can be charged by adapter or usb cable . i have to show screen in both cases. i have done this by implementing SystemListener interface & checking status in batteryStatusChange method. here is my code :-

private boolean _status;
public void batteryStatusChange(int status) {


if(status==DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWE R||status==DeviceInfo.BSTAT_CHARGING||status==Devi ceInfo.BSTAT_AC_CONTACTS){
_status=true;
}
if(_status==true){
do some thing...
}
}

It detects device is charging by usb cable or adapter & works fine for bold os 6.0 but it doesnt detect device is charging or not in bold os 5.0.

Any one knows why this code doesnt work for bold os 5.0?
Offline  
Old 09-19-2011, 09:03 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Blackberry System Listener issues

From the API documentation for SystemListener.batteryStatusChange(int status):
status - A combination of the BSTAT_xxx masks from DeviceInfo.

Status may contain status bits from more than one status. Your tests will not work in such cases.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 09-20-2011, 02:25 AM   #3
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

So, how i can i test in this case . i have checked against all BSTAT_xxx masks related to charging mode.
Offline  
Old 09-20-2011, 05:42 AM   #4
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

in os 6.0 i am testing like this:
if(status==DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWE )

& above condition gives true in bold os 6.0 but in bold os 5.0 above condition gives false because i m getting status zero in os 6.0
Offline  
Old 09-20-2011, 07:51 AM   #5
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Blackberry System Listener issues

Quote:
Originally Posted by msdevaf View Post
So, how i can i test in this case . i have checked against all BSTAT_xxx masks related to charging mode.
Try something along the lines of:

PHP Code:
if ((status DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER) == DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER) {
    ...

or:

PHP Code:
if ((status & (DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWER DeviceInfo.BSTAT_CHARGING Devi ceInfo.BSTAT_AC_CONTACTS)) != 0) {
    ...

Simple boolean algebra.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 09-20-2011, 11:47 PM   #6
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

ok i will try this

Do you know how can i check whether device is charging by adapter or by usb cable? i use this statement to check whether device is charging by adapter or not?

if(status==DeviceInfo.BSTAT_IS_USING_EXTERNAL_POWE R)


if device is charging by adapter this condition gives true but when i charge device by usb cable this condiiton also gives true .

How can i differentiate whether device is charging by adapter or usb cable?
Offline  
Old 09-21-2011, 07:37 AM   #7
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Blackberry System Listener issues

SystemListener2.usbConnectionStateChange(int state)
__________________
My other Blackberry is a PlayBook.
Offline  
Old 09-26-2011, 04:58 AM   #8
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

as you told to use this
SystemListener2.usbConnectionStateChange(int state)

in this method when i plug usb cable in device it gives state 18 i. i am implementing same class wd System Listener also so it also invokes batteryStatusChange(int status) when i plug usb cable

then hw wll i differentiate?
Offline  
Old 09-26-2011, 07:46 PM   #9
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Blackberry System Listener issues

It will do that because the usb connection state changes and the battery status changed (probably because the USB bus was supplying power). You differentiate by interpreting the values of state in the context of the method that is called.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 09-28-2011, 04:03 AM   #10
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

Hi,

To differentiate between usb & adapter charging i make some changes in code. I figure out that when usb is connected then in this method usbConnectionStateChange(int state) state is 18 but when adapter is connected state is 1
so i did this:

public void usbConnectionStateChange(int state) {

if(state!=1){

do what ever you want to do if device is charging by usb

}
}

if adapter is connected to device this method is invoked but since it get state equals to 1 so it does nothing

if usb is connected to device this method is invoked &it get state not equals to 1 so it executes code inside loop

So, half part of my problem is resolved now but since i have to implement functionality if device is charging by adapter so i have implemented that functionality in public void batteryStatusChange(int status)

This method is invoked & it execute code inside loop when device is connected to adapter
But the problem is when device is connected to usb , this method is invoked & it execute code also inside loop. I have use this

public void batteryStatusChange(int status) {
if(status==DeviceInfo.getBatteryStatus()){

do what ever you want to do if device is charging by adapter

}
}

So, how would i compare status so that it execute only when device is connected to adapter?
Offline  
Old 09-28-2011, 07:22 AM   #11
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Blackberry System Listener issues

Quote:
Originally Posted by msdevaf View Post
Hi,

To differentiate between usb & adapter charging i make some changes in code. I figure out that when usb is connected then in this method usbConnectionStateChange(int state) state is 18 but when adapter is connected state is 1
so i did this:

PHP Code:
public void usbConnectionStateChange(int state) {

    if(
state!=1){

        
//do what ever you want to do if device is charging by usb

    
}

if adapter is connected to device this method is invoked but since it get state equals to 1 so it does nothing

if usb is connected to device this method is invoked &it get state not equals to 1 so it executes code inside loop

So, half part of my problem is resolved now but since i have to implement functionality if device is charging by adapter so i have implemented that functionality in public void batteryStatusChange(int status)

This method is invoked & it execute code inside loop when device is connected to adapter
But the problem is when device is connected to usb , this method is invoked & it execute code also inside loop. I have use this

PHP Code:
public void batteryStatusChange(int status) {
    if(
status==DeviceInfo.getBatteryStatus()){

        
//do what ever you want to do if device is charging by adapter

    
}

So, how would i compare status so that it execute only when device is connected to adapter?
There is so much wrong here I don't know where to begin.
  1. If you want people to help you with your code, it is only polite to format it in a way that is easy to read.
  2. you have no way to be sure that the constant values 18 and 1 will be the same under different OS instances let alone different OS versions. Use the defined symbolic constants from the API
  3. once you are properly decoding the status information in a way consistent with the API documentation the way to do what you want should be obvious. It isn't entirely clear to me what you are trying to do so I can't write the code for you.
__________________
My other Blackberry is a PlayBook.

Last edited by hrbuckley; 09-28-2011 at 07:23 AM..
Offline  
Old 10-03-2011, 02:25 AM   #12
msdevaf
Knows Where the Search Button Is
 
Join Date: Sep 2011
Model: 9700
PIN: N/A
Carrier: 9700
Posts: 15
Default Re: Blackberry System Listener issues

I want that this method batteryStatusChange(int status) must be invoked only when device is connected to adapter but this method is also invoked when device is connected to usb
In both cases this statement returns true:
if(status==DeviceInfo.getBatteryStatus()){

//do what ever you want to do if device is charging by adapter

}
so what code should i write so that this method will execute only when device is connected to adapter ?
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads for: Blackberry System Listener issues
Thread Thread Starter Forum Replies Last Post
Bes 4.1.7 Mr2 Mikey_AGBoston BES Admin Corner 5 04-29-2010 02:37 PM
Latest and Greatest Carrier Themes on GSM 8800 dc/dc BlackBerry Themes 13 06-01-2007 09:41 PM
BES for Exchange 4.0.4 Available Now BlackBerryLinks BES Admin Corner 28 05-06-2006 10:38 AM


Samsung, PT212ATP, Integrated Circuit, New, Lot of 13 picture

Samsung, PT212ATP, Integrated Circuit, New, Lot of 13

$195.00



Genuine SAMSUNG Range Oven Relay Board DG92-01207D picture

Genuine SAMSUNG Range Oven Relay Board DG92-01207D

$99.95



Samsung OfficServ 100 Enterprise IP Solution picture

Samsung OfficServ 100 Enterprise IP Solution

$280.00



Samsung, KM2816A-25, Integrated Circuit, New, Lot of 15 picture

Samsung, KM2816A-25, Integrated Circuit, New, Lot of 15

$225.00



NEW Samsung LTM190ET01 LCD Screen Display Panel 19-inch   picture

NEW Samsung LTM190ET01 LCD Screen Display Panel 19-inch

$173.91



New In Box SAMSUNG LTM170EU-L31 LCD Display Panel 17

New In Box SAMSUNG LTM170EU-L31 LCD Display Panel 17"

$188.88







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.