我有一个使用 TTS 读出 GTalk 消息的应用程序。Google Hangouts 取代了 GTalk,所以现在我需要与 Hangouts 集成。我终于得到了一个内容观察者的工作,当环聊收到消息时它会被调用。
getContentResolver().registerContentObserver(
Uri.withAppendedPath(Uri
.parse("content://com.google.android.apps.babel.content.EsProvider/"),
"messages"), true, observer);
当观察者被调用时
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;
}
我收到权限错误。
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)
我还尝试将此权限添加到我的清单中:
com.google.android.apps.babel.content.EsProvider.permission.READ_ONLY
我还发现这个博客描述了一种寻找与此类数据交互的方法的方法。
我对任何可能获取消息发件人和最新消息文本的方法持开放态度。我还没有找到任何关于新环聊的 Android 界面的好的文档。这是 GTalk 的一个非常好的功能,我希望在环聊中获得相同的功能。任何线索,信息,建议都非常感谢。