I have an app that reads out GTalk messages using TTS. Google Hangouts replaced GTalk so now I need to integrate with Hangouts. I finally got a content observer working which gets called when Hangouts gets 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 described an approach to finding way to interface with data like this.
I am open to any methods that may get the message sender and text of the most recent message. I have not found any good documentation on Android interfaces with the new Hangouts. This was a very nice feature with GTalk and I would like to get the same functionality with Hangouts. Any clues, info, suggestions greatly appreciated.