[android-developers] Re: phoneStateListener
I am looking for the same thing.. :) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Phonestatelistener dies after a while .... can it be kept alive?
TelephonyManager tm = (TelephonyManager)getSystemService (TELEPHONY_SERVICE); tm.listen(mPhoneListener, PhoneStateListener.LISTEN_NONE); This seems to work for a while but then fails to fire after - say an hour. This sounds very much like a problem I have and wrote about at http://www.anddev.org/crash_recovery_makes_my_widget_useless-t9163.html I have tried relaunching the listening in a timertask every 60 seconds but this does not seem to work. Yep :-), I have also tried to use a timertask and that get lost as well as the PhoneStateListener together with some other global variables. Is there a way of keeping a listener alive for a long period of time. I wish I knew. The timertask idea might work if the timertask is replaced with an AlarmManager. However, I still don't like the idea to do periodic checks to see if something has become broken. Those periodic checks will consume battery if done often but if done seldom there is instead a bigger risk of not having a working PhoneStateListener when the phone state changes. I can only assume the system is garbage collecting it. According to my studies of the logs it seems as if the PhoneStateListener disappears because the application crashes and then is recovered in a less useful state. regards Henrik -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener::onSignalStrengthChanged
Not quite, the original way passed an int not a SignalStrength class, i dont think SignalStrength is part of the SDK yet. They say its been deprecated, i assume this means a soon to come revision of the SDK will have this class in and fixed. You will have to wait for a google developer to confirm this. Ne0 On Nov 17, 5:48 pm, Ken Adair kadai...@gmail.com wrote: Thanks for the reply. The way you mentioned was the way to do it prior to Android 2.0. However, it has since been deprecated, meaning that is no longer the way to access signal strength. From my limited testing this method no longer seems to work when testing with the Droid. On Nov 17, 12:30 pm, Master_Ne0 master.ne0s.soluti...@googlemail.com wrote: The source code suggests this, @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { mSignalStrength = signalStrength; updateSignalStrength(); } where SignalStrength is android.telephony.SignalStrength class. Let me know if this works, doubt that it will be backwards compatible. Ne0 On Nov 17, 1:46 am, Ken Adair kadai...@gmail.com wrote: I'm assuming it is returning -1 because it is no longer being used with 2.0? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener::onSignalStrengthChanged
The source code suggests this, @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { mSignalStrength = signalStrength; updateSignalStrength(); } where SignalStrength is android.telephony.SignalStrength class. Let me know if this works, doubt that it will be backwards compatible. Ne0 On Nov 17, 1:46 am, Ken Adair kadai...@gmail.com wrote: I'm assuming it is returning -1 because it is no longer being used with 2.0? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener::onSignalStrengthChanged
Thanks for the reply. The way you mentioned was the way to do it prior to Android 2.0. However, it has since been deprecated, meaning that is no longer the way to access signal strength. From my limited testing this method no longer seems to work when testing with the Droid. On Nov 17, 12:30 pm, Master_Ne0 master.ne0s.soluti...@googlemail.com wrote: The source code suggests this, @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { mSignalStrength = signalStrength; updateSignalStrength(); } where SignalStrength is android.telephony.SignalStrength class. Let me know if this works, doubt that it will be backwards compatible. Ne0 On Nov 17, 1:46 am, Ken Adair kadai...@gmail.com wrote: I'm assuming it is returning -1 because it is no longer being used with 2.0? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener::onSignalStrengthChanged
I second the SDK confusion. I was able to create a PhoneStateListener and override the onSignalStrengthChanged method. However, the asu is always -1. I am also testing on the Droid. Someone at Google please advise. Regards, Ken -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener::onSignalStrengthChanged
I'm assuming it is returning -1 because it is no longer being used with 2.0? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: PhoneStateListener memory leak
When you do this kind of test, you should force GCs on the system process with DDMS, then force GCs in your process and then check how many activities you have running. On Tue, Sep 8, 2009 at 10:57 AM, Flying Coderav8r.st...@gmail.com wrote: There appears to be a leak when using PhoneStateListeners. The following code simply reigsters in onResume and unregisters in onPause a PhoneStateListener. Repeatedly launch then press BACK (so the app is finished onDestory is called before the next launch) and the number of activities reported by meminfo will equal the number of launches. For instance, here is the output I get after launching (and finishing) 11 times in sequence: dumpsys meminfo com.example.leak Currently running services: meminfo --- DUMP OF SERVICE meminfo: Applications Memory Usage (kB): Uptime: 12204322 Realtime: 12204322 ** MEMINFO in pid 1358 [com.example.leak] ** native dalvik other total size: 2648 3079 N/A 5727 allocated: 2604 2254 N/A 4858 free: 43 825 N/A 868 (Pss): 913 1305 1475 3693 (shared dirty): 1080 3864 568 5512 (priv dirty): 808 936 1056 2800 Objects Views: 77 ViewRoots: 1 AppContexts: 12 Activities: 11 Assets: 2 AssetManagers: 2 Local Binders: 36 Proxy Binders: 21 Death Recipients: 0 OpenSSL Sockets: 0 SQL heap: 0 dbFiles: 0 numPagers: 0 inactivePageKB: 0 activePageKB: 0 # Without the PhoneStateListener, the number of activities is always 1 no matter how many times the app is launched finished. So, am I doing anything wrong here? Or is this a bug in the TelephonyManager? Thanks, Steve here's the code package com.example.leak; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; public class LeakExample extends Activity { private class MyPhoneStateListener extends PhoneStateListener { �...@override public void onCallStateChanged(int state, String incomingNumber) { if ((state == TelephonyManager.CALL_STATE_RINGING) || (state == TelephonyManager.CALL_STATE_OFFHOOK)) { LeakExample.this.finish(); } } } MyPhoneStateListener phone_listener = new MyPhoneStateListener(); TelephonyManager telMgr ; �...@override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); telMgr = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE); } �...@override protected void onPause() { super.onPause(); telMgr.listen(phone_listener, PhoneStateListener.LISTEN_NONE); } �...@override protected void onResume() { super.onResume(); telMgr.listen(phone_listener, PhoneStateListener.LISTEN_CALL_STATE); } �...@override protected void onDestroy() { super.onDestroy(); Log.v(LEAK EXAMPLE, onDestory); } } -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: PhoneStateListener memory leak
Ugh -- yep, that was the problem. Thanks! :-) On Sep 8, 2:04 pm, Romain Guy romain...@google.com wrote: When you do this kind of test, you should force GCs on the system process with DDMS, then force GCs in your process and then check how many activities you have running. On Tue, Sep 8, 2009 at 10:57 AM, Flying Coderav8r.st...@gmail.com wrote: There appears to be a leak when using PhoneStateListeners. The following code simply reigsters in onResume and unregisters in onPause a PhoneStateListener. Repeatedly launch then press BACK (so the app is finished onDestory is called before the next launch) and the number of activities reported by meminfo will equal the number of launches. For instance, here is the output I get after launching (and finishing) 11 times in sequence: dumpsys meminfo com.example.leak Currently running services: meminfo --- DUMP OF SERVICE meminfo: Applications Memory Usage (kB): Uptime: 12204322 Realtime: 12204322 ** MEMINFO in pid 1358 [com.example.leak] ** native dalvik other total size: 2648 3079 N/A 5727 allocated: 2604 2254 N/A 4858 free: 43 825 N/A 868 (Pss): 913 1305 1475 3693 (shared dirty): 1080 3864 568 5512 (priv dirty): 808 936 1056 2800 Objects Views: 77 ViewRoots: 1 AppContexts: 12 Activities: 11 Assets: 2 AssetManagers: 2 Local Binders: 36 Proxy Binders: 21 Death Recipients: 0 OpenSSL Sockets: 0 SQL heap: 0 dbFiles: 0 numPagers: 0 inactivePageKB: 0 activePageKB: 0 # Without the PhoneStateListener, the number of activities is always 1 no matter how many times the app is launched finished. So, am I doing anything wrong here? Or is this a bug in the TelephonyManager? Thanks, Steve here's the code package com.example.leak; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; public class LeakExample extends Activity { private class MyPhoneStateListener extends PhoneStateListener { �...@override public void onCallStateChanged(int state, String incomingNumber) { if ((state == TelephonyManager.CALL_STATE_RINGING) || (state == TelephonyManager.CALL_STATE_OFFHOOK)) { LeakExample.this.finish(); } } } MyPhoneStateListener phone_listener = new MyPhoneStateListener(); TelephonyManager telMgr ; �...@override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); telMgr = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE); } �...@override protected void onPause() { super.onPause(); telMgr.listen(phone_listener, PhoneStateListener.LISTEN_NONE); } �...@override protected void onResume() { super.onResume(); telMgr.listen(phone_listener, PhoneStateListener.LISTEN_CALL_STATE); } �...@override protected void onDestroy() { super.onDestroy(); Log.v(LEAK EXAMPLE, onDestory); } } -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: PhoneStateListener state transitions
Also, adding/receiving other calls while on an existing doesn't seem to send any new events. On Feb 8, 3:21 am, songs coca.c...@gmail.com wrote: Hi, I'm a little confused by what I'm seeing with regards to phone state transitions via the PhoneStateListener. When I receive a call, this is what happens: (call comes in) RINGING - IDLE (I pick up) OFFHOOK (I hang up) IDLE It's that first transition from RINGING to IDLE without any interaction from me (not ending the call, not answering the call) that confuses me. Do I really have to implement an idle counter to know that an incoming call has really ended? Seems like the reported phone state represents some sort of phone state that isn't the obvious one... Is this a bug or am I just not in tune with the paradigm here? Regards, Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: PhoneStateListener GarbageCollection
Having the same problem with the PhoneStateListener. Did you manage to keep it alive? Regarding services, this might help: http://groups.google.com/group/android-developers/browse_frm/thread/fa2848e31636af70?hl=en On Dec 3, 3:21 pm, blau vinb...@gmail.com wrote: I'm trying to figure out the best way to have a PhoneStateListener survive as long as possible and be recreated if necessary. TelephonyManager telephonyManager = (TelephonyManager) aContext.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); // I'm setting that up on BOOT_COMPLETED, and it survives for a while, but eventually garbage collection kicks in and seems to kill my listener. Setting a service up that just holds a reference would work right? But what concerns do I need to have about services dieing? Anyone have an idea why phone states weren't implemented as a broadcast intent? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: phoneStateListener
Anyone ? On Nov 3, 12:32 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I think I got this straight. Now an other problem - I want to use the 'onCallStateChanged' function to launch my app screen when a call ends. How do I bring my app to the front ? TIA On Oct 9, 8:22 pm, chouman82 [EMAIL PROTECTED] wrote: Can anyone give a simple example of the usage ofPhoneStateListener? I have tried to overwrite the listener and register it with the TelephonyManager with the Context.TELEPHONY_SERVICE. But i only saw my logging statement printed out right when I started to run the application. The logging showed the PhoneState as IDLE. But then after that when I use telnet to emulate an incoming call, I don't see the logging statement been printed for PhoneState - RINGING or PhoneState - OFFHOOK. here is my code snippet: TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); tm.listen(this, CallStateListener.LISTEN_CALL_STATE); public void onCallStateChanged(int state, String incomingNumber) { switch(state) { case TelephonyManager.CALL_STATE_DLE: Log.d(DEBUG, PHONE STATE - IDLE); break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d(DEBUG, PHONE STATE - OFFHOOK); break; case TelephonyManager.CALL_STATE_RINGING: Log.d(DEBUG, PHONE STATE - RINGING); break; } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: PhoneStateListener not called until Phone Activity completes...
I thinks I answered my own question again. The problem appears to be with the Android Service object. I was using an instance of the Service object to do my synchronization. In normal Java, when you call wait() inside of a synchronization block, the thread is supposed to release the monitor so that the thread can be notified ( ... because notify() must also be called from within a synchronization block.) It appears the Android Service object does not behave according to normal Java semantics i.e., it doesn't release the monitor when wait() is called. Therefore, notify() can't enter the monitor in order to wake up the thread and therefore, the wait always times out. The simple solution is to use another object as the synchronizer. I guess Service can be viewed as a special OS object with unique restrictions so it's understandable. However, this fact should definitely be placed in the documentation - yo Google. On Nov 17, 1:57 pm, dreamerBoy [EMAIL PROTECTED] wrote: Hi - I'm having a problem with my PhoneStateListener not being called until after the Phone Activity is finished. Here is what I am doing: step 1: Install a PhoneStateListener. The listener is supposed to call notify() (synchronized on the lock object) when it detects a change in the phone state (specifically OFF_HOOK). step 2: Place a call with the ACTION_CALL intent. step 3: Call wait(timeout) (in a synchronized loop), waiting for the listener to wake us up. (I realize wait/notify can be tricky but am confident the implementation is correct...) Step 3 is always appearing to time out even though I am seeing the call go through properly on the emulator screen. No matter what timeout value I use, it always times out even though telephonyManager.getCallState() returns the correct value (OFF_HOOK). I tried placing step 2 and step 3 in their own, separate (ordinary Java) threads. Same behavior. When I tried placing step 1 in its own (ordinary Java) thread, Android throws: 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): Uncaught handler: thread Thread-9 exiting due to uncaught exception 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at android.os.Handler.init(Handler.java:111) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at android.telephony.PhoneStateListener$2.init(PhoneStateListener.java: 235) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at android.telephony.PhoneStateListener.init(PhoneStateListener.java: 234) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at test.phone.PhoneTestService$MyPhoneStateListener.init (PhoneTestService.java:529) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at test.phone.PhoneTestService$MyPhoneStateListener.init (PhoneTestService.java:529) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at test.phone.PhoneTestService.listenToCallState(PhoneTestService.java: 640) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at test.phone.PhoneTestService.access$2(PhoneTestService.java:618) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at test.phone.PhoneTestService$1.run(PhoneTestService.java:704) 11-17 12:12:01.451: ERROR/AndroidRuntime(2004): at java.lang.Thread.run(Thread.java:935) Working on figuring out the right way to launch the listener in a Handler thread - however, there's nothing in the PhoneStateListener write-up about having to launch in a separate execution context. This doesn't seem to follow Java orthodoxy either - e.g., in Swing, callbacks are invoked seamlessly - no separate execution context required. ...Unless - I've overlooked something ... Can anyone shed any light on this? Thanks much. -dreamer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: PhoneStateListener not being called back
Answered my own question... telMgr.listen(myPhoneStateListener, TelephonyManager.CALL_STATE_IDLE | TelephonyManager.CALL_STATE_RINGING | TelephonyManager.CALL_STATE_OFFHOOK); is wrong. This is right: telMgr.list(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); of course - one still uses TelephoneManager.CALL_STATE_IDLE in onCallStateChangedChanged so it's a bit tricky. Hey Google, Java has enums yes? On Nov 13, 4:24 pm, dreamerBoy [EMAIL PROTECTED] wrote: I didn't forget: uses-permission android:name=android.permission.READ_PHONE_STATE/ uses-permission On Nov 13, 4:09 pm,dreamerBoy[EMAIL PROTECTED] wrote: private class MyPhoneStateListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { log(listener call state: + phoneStateToString(state) + + new Date()); } } MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener (); /* * telMgr.listen(myPhoneStateListener, TelephonyManager.CALL_STATE_IDLE * | TelephonyManager.CALL_STATE_RINGING | * TelephonyManager.CALL_STATE_OFFHOOK); */ // let's try this... telMgr.listen(myPhoneStateListener, TelephonyManager.CALL_STATE_IDLE); telMgr.listen(myPhoneStateListener, TelephonyManager.CALL_STATE_RINGING); telMgr.listen(myPhoneStateListener, TelephonyManager.CALL_STATE_OFFHOOK); Intent myIntent = new Intent(Intent.ACTION_CALL, Uri.parse(tel: 1234567)); thisActivity.startActivity(myIntent); I can see the call definitely get placed on the emulator - however, no PhoneStateListener callback. I can always resort to polling with telMgr.getCallState() but it's not as elegant as a callback - anyway, wondering what's up. -dreamer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: phoneStateListener
Hi, I think I got this straight. Now an other problem - I want to use the 'onCallStateChanged' function to launch my app screen when a call ends. How do I bring my app to the front ? TIA On Oct 9, 8:22 pm, chouman82 [EMAIL PROTECTED] wrote: Can anyone give a simple example of the usage of PhoneStateListener? I have tried to overwrite the listener and register it with the TelephonyManager with the Context.TELEPHONY_SERVICE. But i only saw my logging statement printed out right when I started to run the application. The logging showed the PhoneState as IDLE. But then after that when I use telnet to emulate an incoming call, I don't see the logging statement been printed for PhoneState - RINGING or PhoneState - OFFHOOK. here is my code snippet: TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); tm.listen(this, CallStateListener.LISTEN_CALL_STATE); public void onCallStateChanged(int state, String incomingNumber) { switch(state) { case TelephonyManager.CALL_STATE_DLE: Log.d(DEBUG, PHONE STATE - IDLE); break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d(DEBUG, PHONE STATE - OFFHOOK); break; case TelephonyManager.CALL_STATE_RINGING: Log.d(DEBUG, PHONE STATE - RINGING); break; } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---