Reading Google Hangouts Messages Using Android

I have an application that reads GTalk messages using TTS. Google Hangouts has replaced GTalk, so now I need to integrate with Hangouts. I finally got a content watcher job that gets called when Hangouts receives a message.

getContentResolver().registerContentObserver( Uri.withAppendedPath(Uri .parse("content://com.google.android.apps.babel.content.EsProvider/"), "messages"), true, observer); 

When the observer is called

  public void onChange(final boolean selfChange) { if (paused) { Toast.makeText(application, "paused", Toast.LENGTH_LONG).show(); return; } Cursor message = null; Cursor conversation = null; Cursor contact = null; //Toast.makeText(application, "getting messages", Toast.LENGTH_LONG).show(); try { final String[] messageProjection = new String[] { "body", "date", "type" }; /*message = getContentResolver() .query(Uri.withAppendedPath( Uri.parse("content://com.google.android.providers.talk/"), "messages"), messageProjection, "err_code = 0", null, "date DESC");*/ message = getContentResolver() .query(Uri.withAppendedPath( Uri.parse("content://com.google.android.apps.babel.content.EsProvider/"), "messages"), messageProjection, "err_code = 0", null, "date DESC"); if (!message.moveToFirst()) { Toast.makeText(application, "no messages", Toast.LENGTH_LONG).show(); return; } 

I get a permission error.

 05-26 07:45:12.262: E/AndroidRuntime(9580): FATAL EXCEPTION: TalkThread 05-26 07:45:12.262: E/AndroidRuntime(9580): java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.babel.content.EsProvider from ProcessRecord{413dcdb8 9580:a2dp.Vol/u0a10071} (pid=9580, uid=10071) that is not exported from uid 10005 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.os.Parcel.readException(Parcel.java:1425) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.os.Parcel.readException(Parcel.java:1379) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2545) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4647) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2054) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1101) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.content.ContentResolver.query(ContentResolver.java:356) 05-26 07:45:12.262: E/AndroidRuntime(9580): at android.content.ContentResolver.query(ContentResolver.java:315) 05-26 07:45:12.262: E/AndroidRuntime(9580): at a2dp.Vol.service$TalkObserver.onChange(service.java:1724) 

I also tried adding this permission to my manifest:

 com.google.android.apps.babel.content.EsProvider.permission.READ_ONLY 

I also found this blog that describes an approach to finding a way to interact with such data.

I am open to any methods that can receive the sender of the message and the text of the most recent message. I did not find any good documentation on Android interfaces with the new Hangouts. It was a very nice feature with GTalk, and I would like to get the same functionality with Hangouts. Any tips, information, suggestions were highly appreciated.

+4
source share
1 answer

Finally, I decided to read the notifications using the Accessibility Service. This is very convenient for most applications. For Hangouts, it reads the first unread message from each sender, but subsequent messages will only report the sender’s name and then β€œn new messages”.

The source code for my project is here: http://code.google.com/p/a2dpvolume/

Take a look at Access.java for the most part. This is an accessibility service for my application. This page: http://code.google.com/p/a2dpvolume/wiki/Accessibility_Settings explains how my application uses it.

+1
source

Source: https://habr.com/ru/post/1482831/


All Articles