How can I get the last call number without using the READ_CALL_LOG permission?
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
How can I get the last call number without using the READ_CALL_LOG permission?
2
Answers
Not possible without permission
1.Add the required permissions to your AndroidManifest.xml file:
2.In your activity or fragment class, import the necessary classes:
3.Check and request the necessary permissions:
4.Handle the permission request result:
5.Implement the method to retrieve the last call number:
In the getLastCallNumber() method, we query the CallLog content provider to retrieve the call log data ordered by date in descending order. We extract the number of the first entry (which will be the last call) and store it in the lastCallNumber variable.
Make sure to handle any necessary error checking, null checks, and close the cursor properly.
Remember to handle the case where the permission is denied and provide appropriate feedback or alternative behavior in your application.