问题描述
我有一些非常简单的code在我的应用程序调用,在Android 1.6的工作,但现在是在对Droid的Android 2.1打破了我一个已知的良好接触索引的编辑联系人的活动。我构建了一个简单的活动/应用空间Edcon
来显示这一点:
I had some fairly simple code in my app to invoke an Edit Contact activity on a known good contact index that worked in Android 1.6 but is broken for me now in Android 2.1 on the Droid. I built a sample activity/app EdCon
to show this:
package com.jbh;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class EdCon extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Build an intent to edit a known good contact index
Intent i;
i = new Intent(Intent.ACTION_EDIT);
i.setData(Uri.parse("content://contacts/people/10"));
startActivity(i);
}
}
当我在我的G1运行1.6它将按预期工作,即会弹出编辑联系人屏幕为知名指数,然后我就可以打回返回运行此的Hello World,空间Edcon。
When I run this on my G1 running 1.6 it works as expected i.e. brings up the Edit Contact screen for the known index and then I can hit BACK to return to "Hello World, EdCon".
当我2.1下Droid手机运行此我得到以下几点:
When I run this on the Droid under 2.1 I get the following:
05-07 15:35:57.787: INFO/ActivityManager(1013): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.jbh/.EdCon }
05-07 15:35:57.826: DEBUG/AndroidRuntime(13780): Shutting down VM
05-07 15:35:57.826: DEBUG/dalvikvm(13780): DestroyJavaVM waiting for non-daemon threads to exit
05-07 15:35:57.928: DEBUG/dalvikvm(13780): DestroyJavaVM shutting VM down
05-07 15:35:57.928: DEBUG/dalvikvm(13780): HeapWorker thread shutting down
05-07 15:35:57.928: DEBUG/dalvikvm(13780): HeapWorker thread has shut down
05-07 15:35:57.928: DEBUG/jdwp(13780): JDWP shutting down net...
05-07 15:35:57.928: DEBUG/jdwp(13780): Got wake-up signal, bailing out of select
05-07 15:35:57.928: INFO/dalvikvm(13780): Debugger has detached; object registry had 1 entries
05-07 15:35:57.928: DEBUG/dalvikvm(13780): VM cleaning up
05-07 15:35:57.935: INFO/ActivityManager(1013): Start proc com.jbh for activity com.jbh/.EdCon: pid=13802 uid=10052 gids={1015}
05-07 15:35:57.967: ERROR/AndroidRuntime(13780): ERROR: thread attach failed
05-07 15:35:58.053: INFO/ActivityThread(13792): Publishing provider com.android.vending.SuggestionsProvider: com.android.vending.SuggestionsProvider
05-07 15:35:58.154: INFO/dalvikvm(13802): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=38)
05-07 15:35:58.209: DEBUG/dalvikvm(13780): LinearAlloc 0x0 used 639500 of 5242880 (12%)
05-07 15:35:58.365: INFO/dalvikvm(13802): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=18)
05-07 15:35:58.639: INFO/ActivityManager(1013): Starting activity: Intent { act=android.intent.action.EDIT dat=content://contacts/people/10 cmp=com.android.contacts/.ui.EditContactActivity }
05-07 15:35:58.975: DEBUG/dalvikvm(13137): GC freed 2902 objects / 166768 bytes in 61ms
05-07 15:35:59.100: DEBUG/vending(13792): com.android.vending.LocalDbSyncService.run(): Syncing local DB with package manager...
05-07 15:35:59.100: DEBUG/vending(13792): com.android.vending.LocalDbSyncService.syncLocalDbWithPackageManager(): No INSTALLING or UNINSTALLING assets.
05-07 15:35:59.115: INFO/ActivityManager(1013): Displayed activity com.android.contacts/.ui.EditContactActivity: 387 ms (total 1296 ms)
05-07 15:35:59.185: DEBUG/Sources(13137): Creating external source for type=com.facebook.auth.login, packageName=com.facebook.katana
05-07 15:35:59.225: DEBUG/vending(13792): com.android.vending.LocalDbSyncService.run(): Syncing done.
05-07 15:35:59.232: WARN/dalvikvm(13137): threadid=27: thread exiting with uncaught exception (group=0x4001b180)
05-07 15:35:59.232: ERROR/AndroidRuntime(13137): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): java.lang.RuntimeException: An error occured while executing doInBackground()
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.os.AsyncTask$3.done(AsyncTask.java:200)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.lang.Thread.run(Thread.java:1096)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): Caused by: android.database.sqlite.SQLiteException: **no such column: raw_contact_id:** , while compiling: SELECT account_name, account_type, sourceid, version, dirty, data_id, res_package, mimetype, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12, data13, data14, data15, data_sync1, data_sync2, data_sync3, data_sync4, _id, is_primary, is_super_primary, data_version, group_sourceid, sync1, sync2, sync3, sync4, deleted, contact_id, starred, is_restricted FROM contact_entities_view WHERE (1) AND (raw_contact_id=10)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1221)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:316)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:3850)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:3840)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.providers.contacts.ContactsProvider2$RawContactsEntityIterator.<init>(ContactsProvider2.java:4498)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.providers.contacts.ContactsProvider2.queryEntities(ContactsProvider2.java:4751)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.content.ContentProvider$Transport.queryEntities(ContentProvider.java:140)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.content.ContentProviderClient.queryEntities(ContentProviderClient.java:98)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.content.ContentResolver.queryEntities(ContentResolver.java:296)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.contacts.model.EntitySet.fromQuery(EntitySet.java:72)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.contacts.ui.EditContactActivity$QueryEntitiesTask.doInBackground(EditContactActivity.java:191)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.contacts.ui.EditContactActivity$QueryEntitiesTask.doInBackground(EditContactActivity.java:154)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at com.android.contacts.util.WeakAsyncTask.doInBackground(WeakAsyncTask.java:45)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-07 15:35:59.295: ERROR/AndroidRuntime(13137): ... 4 more
05-07 15:35:59.303: INFO/Process(1013): Sending signal. PID: 13137 SIG: 3
05-07 15:35:59.303: INFO/dalvikvm(13137): threadid=7: reacting to signal 3
05-07 15:35:59.303: ERROR/dalvikvm(13137): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-07 15:35:59.506: INFO/DumpStateReceiver(1013): Added state dump to 1 crashes
05-07 15:36:07.053: DEBUG/dalvikvm(12901): GC freed 389 objects / 25056 bytes in 145ms
05-07 15:36:17.287: DEBUG/dalvikvm(11649): GC freed 154 objects / 6816 bytes in 136ms
05-07 15:36:22.365: DEBUG/dalvikvm(13574): GC freed 348 objects / 67848 bytes in 112ms
05-07 15:36:27.451: DEBUG/dalvikvm(11836): GC freed 267 objects / 17432 bytes in 65ms
05-07 15:36:32.553: DEBUG/dalvikvm(12757): GC freed 1888 objects / 92440 bytes in 67ms
05-07 15:36:38.803: INFO/power(1013): *** set_screen_state 0
05-07 15:36:38.813: DEBUG/SurfaceFlinger(1013): About to give-up screen, flinger = 0x114c30
05-07 15:36:38.826: DEBUG/Sensors(1013): using accelerometer (name=accelerometer)
05-07 15:36:38.834: DEBUG/PhoneWindow(13137): couldn't save which view has focus because the focused view android.widget.ScrollView@44883558 has no id.
05-07 15:36:38.865: DEBUG/WifiService(1013): ACTION_SCREEN_OFF
05-07 15:36:38.889: DEBUG/WifiService(1013): setting ACTION_DEVICE_IDLE timer for 900000ms
05-07 15:36:44.107: DEBUG/dalvikvm(1013): GC freed 7351 objects / 521440 bytes in 130ms
05-07 15:36:49.373: DEBUG/dalvikvm(13553): GC freed 321 objects / 12056 bytes in 102ms
的没有这样的列:raw_contact_id:
看起来像这个问题,但我不知道怎么样
或为什么会发生,或者是什么意思。任何帮助AP preciated!
The no such column: raw_contact_id:
looks like the issue but I'm not sure howor why that would happen or what it means. Any help appreciated!
推荐答案
好吧,经过一番实验,以下code对我的作品,这是我使用的是什么(尽管它似乎比它更多的工作应):
Ok, after some experimentation, the following code works for me and this is what I'm using (although it seems a bit more work than it should be):
// contname is a String that was passed in
Uri lkup = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, contname);
Cursor idCursor = c.getContentResolver().query(lkup, null, null, null, null);
long lid = KSConstants.INVALIDLONG;
if(idCursor.moveToFirst()) {
int idIdx = idCursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID);
lid = idCursor.getLong(idIdx);
}
idCursor.close();
// Now use the ID and name in a lookup to guarantee we get the right contact for editing.
if(lid == KSConstants.INVALIDLONG) return;
lkup = ContactsContract.Contacts.getLookupUri(lid,contname);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(lkup);
c.startActivity(i);
这篇关于编辑联系人code在1.6工作,但对Droid的2.1不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!