我有一個使用TTS讀取GTalk消息的app。 Google環聊取代了GTalk,現在我需要與環聊進行整合。我終於得到了一個內容觀察員工作,當環聊收到消息時會被調用。使用Android閱讀Google環聊消息
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
我還發現,描述的方法尋找方式與這樣的數據接口this blog。
我接受任何方法,可能會收到消息發件人和最新消息的文本。我還沒有發現有關新版環聊的Android界面上的任何優秀文檔。這是GTalk的一個非常棒的功能,我希望通過環聊獲得相同的功能。任何線索,信息,建議非常感謝。
jroal,您可以添加更多關於如何使用輔助功能服務的詳細信息嗎? – guiomie
詳情請見上面的鏈接:http://code.google.com/p/a2dpvolume/wiki/Accessibility_Settings – jroal