Get WhatsApp messages
Whatsapp did not publish any official APIs.
There's this open source API for communicating with whatsapp, it's not official and might stop working if Whatsapp update their protocols.
https://github.com/venomous0x/WhatsAPI
Regarding the legality of using this or other non-official API, it depends on the service agreement that you agreed to with Whatsapp. Read it and see if they frown upon using their communication protocols with clients other than theirs. My guess would be they do not allow it.
UPDATE: This GitHub repository seems to have been taken offline due to legal threats.
How to get received whatsapp messages programmatically?
I may have 2 solutions:
Check every x seconds for unread messages and save the id of this message. Next time check again for unread messages which have an id higher than the previous one. Then the app knows which message is new and can read all new ones.
Use AccessibilityService to get notificated when a new message from whatsapp was received and follow the same steps.
Tell me if it helped or if it's a bad idea :D
Related Topics
Disconnect a Bluetooth Socket in Android
Navigation Drawer: Set as Always Opened on Tablets
Incompatible Plugins for Android-Apt After Upgrading to Android Studio 2.3
Memory Leaks with Custom Font for Set Custom Font
Toggle Button Using Two Image on Different State
Trying to Get the Display Size of an Image in an Imageview
What Is the Use of the Res/Values/Public.Xml File on Android
How to Animate a View with Translate Animation in Android
Fragments Onresume from Back Stack
Android Recyclerview:Notifydatasetchanged() Illegalstateexception
Android - Custom UI with Custom Attributes
Android - Configure Spinner to Use Array
How Is Staticlayout Used in Android
Android Volley + JSONobjectrequest Caching
Is There a Simple Example of the Popupwindow Class Using Android V2.0