PhoneStateListen | int state , String incomingNumber
kandi X-RAY | PhoneStateListen Summary
kandi X-RAY | PhoneStateListen Summary
然后通过PhoneStateListener的回调方法onCallStateChanged(int state, String incomingNumber) 实现来电的监听 (详细实现可以参考后面给出的拓展阅读部分).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- On call state changed
- Get the telephony service
- End the phone call
- Disconnect a service call
- OnClick callback
- Register phone state listener
- Override this method to handle the phone state listener
- Register a custom phone state listener
- RegionBind method
- Override this method to be called when the application is rebinding
- Destroys the container
- On create
- Handle phone call
- Override this method to handle the custom phone state changes
- Called when the activity is saved
- Kill call
- On unbind event
PhoneStateListen Key Features
PhoneStateListen Examples and Code Snippets
Community Discussions
Trending Discussions on PhoneStateListen
QUESTION
This PhoneStateListener only works if the app is open for API>28(P) but i want the incoming/outgoing phone number even if the app is closed just like it works in API<=28(P). i am getting the phone number if the app is open at the time of call, but otherwise number is coming as blank.
...ANSWER
Answered 2021-Dec-14 at 16:46It is normal behavior for Android OS to protect user privacy against malicious apps from stealing user information. However, You can resolve the problem by using a System Event Broadcast Receiver to be notified of incoming phone calls. Here is a good example to follow. The example is not enough and applicable for current android API levels and you need to have a Foreground Service when a call is received then run the Foreground Service and execute your codes.
QUESTION
I'd like to listen if there's a phone call happening while my app is in the foreground.
It was like this before but now listen() is deprecated:
...ANSWER
Answered 2021-Nov-09 at 13:58I used what you did and android 12 emulator also worked.I used this for versions less than android 12 I hope it works.
QUESTION
In my app I m detecting the incoming calls phone number , everything working fine but when I m trying to set the phone number in the textview of main activity I m getting below errors
Errors
...ANSWER
Answered 2021-May-23 at 17:52You never initialize the variable mainActivity
in your BroadcastReceiver
. That is why you are getting a NullPointerException.
However, the approach you are using is not good. You should never access UI components (in this case a TextView
) from a BroadcastReceiver
directly. The BroadcastReceiver
should pass the data to your Activity
and the Activity
can then manipulate the UI components. If your BroadcastReceiver
is an inner class of the Activity
, it can simply call a method on the Activity
to update the TextView
.
QUESTION
I have two application class which I want to combine in one, but provides two function, but I want it only one class so that I can call it on the application class in my manifest and get the App to produce both functions since i can not have two classes called on the application class in my manifest file in android studo.
I would like to put the AppController class in the App.Java class
Where I am confused is how to combine it since both extends different classes which java does not permit extending two classes in one.
Below is the App.java class
...ANSWER
Answered 2021-May-20 at 13:47MulitdexApplication extends Application. You could change your AppController to:
QUESTION
My service has a PhoneStateListener that overrides the onCellInfoChanged method. When running on Android Studio, it'll log whenever the method is called. Based on the logs, it seems that sometimes the method gets called consecutively (a couple milliseconds between logs).
...ANSWER
Answered 2020-Nov-23 at 11:00The callbacks from PhoneStateListener
are all made on the main (UI) thread. Therefore, each callback method will run to completion before the next one is called.
QUESTION
I'm facing an issue with getAllCellInfo()
.
App has permissions needed :
here is my code :
1- listener
...ANSWER
Answered 2020-Nov-14 at 17:38Resolved :
This issue is related to some dual SIM phones
QUESTION
I'm currently working on an android application to monitor the incoming and outgoing calls from a phone and register the call info into a file, and from what I've read PhoneStateListener
seems to do what I need.
The thing is I need the application to run on background and I was thinking of using a service for that, but every example I've found that uses the listener declares it in the main activity, so I'm not sure if I need to create a service for it to run on background.
For a little more context, I have specific instructions that I can't create an application to "replace" the default calling app, so there's not much use in creating a GUI (I know the app needs a main activity, but it's only functionality should be starting the monitor).
The idea I have at the moment looks something like:
...ANSWER
Answered 2020-Sep-29 at 19:14You need to move your listener into Service
that will be running standalone. The service is already in "background", so you don't need to create extra thread. Moreover, from what you have posted there is no code that is blocking code, all your events will be sent in callback manner.
QUESTION
I want to run my android application always in background like whatsapp,truecaller i have used all things but when device is reboot the application is stop running in background for that i have used broadcast receiver to listen boot. here is my code.
My Service
public class Myservice extends Service {
...ANSWER
Answered 2020-Sep-18 at 09:34You can use JobService android.intent.action.BOOT_COMPLETED this method is not worked on latest version of Android.
JobServiceQUESTION
I want to get currently cell information in use for data transmit. Before Android Q, I can get it easily via getallcellinfo(). However, beginning with Android Q, this will be reported via onCellInfoChanged().
I don't need to listen on the changed of cell information, I just need the cell information at the moment that the method is called. I cannot just return ((CellInfoLte) cellInfo).getCellIdentity().getEarfcn();
inside PhoneStateListener. How to implement this?
ANSWER
Answered 2020-Sep-09 at 09:57You can't use return. Create an interface same
QUESTION
I'm currently building a spam-call blocking app as a fun project to get better with Android development, and am running into this odd bug.
I have a Broadcast Receiver setup to listen for changes in the call state, and logic to check if the call is incoming or not, and basically end the call if the number is not in the user's contact list or a "whitelist" of approved numbers held in a database. However, even after the call has been ended, the receiver continues to be called multiple times (sometimes 8 or more times) and will often be called with Call State set as ringing (again, despite the fact that the call has been ended).
Basically, I'm trying to keep track of how many times each unknown number calls the phone, but for each single call it records it as anywhere from 2 - 6 calls.
Here is the onReceive function I have set up:
...ANSWER
Answered 2020-Aug-24 at 08:16There are two ways to get callbacks when the phone state changes: PhoneStateListener
and a BroadcastReceiver
that listens to android.intent.action.PHONE_STATE
.
It looks like you're mixing the two methods together, which means that whenever your BroadcastReceiver is called, you're registering another new PhoneStateListener
, so you keep adding more and more listeners that do the same thing.
I would recommend not using PhoneStateListener
at all, and go with the BroadcastReceiver
approach only, which can be setup via AndroidManifest
which allows it to be called even when the app is asleep.
See this tutorial: https://medium.com/@saishaddai/how-to-know-when-a-device-is-ringing-in-android-57e516d0ab42
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PhoneStateListen
You can use PhoneStateListen like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the PhoneStateListen component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page