2010-05-07 60 views
2

我的應用程序中有一些相當簡單的代碼,用於在Android 1.6中工作的已知良好聯繫人索引上調用編輯聯繫人活動,但現在已爲我打破Droid上的Android 2.1。我建了一個樣本活動/應用EdCon表明這一點:編輯聯繫人代碼工作在1.6,但不能在Droid 2.1上工作

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); 
    } 
} 

當我上運行1.6它將按預期工作即會彈出編輯聯繫人屏幕爲已知的索引,然後我可以背打我的G1運行這個返回到「Hello World,EdCon」。

當我2.1下的Droid手機運行此我得到如下:

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 [email protected] 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 

no such column: raw_contact_id:看起來像這個問題,但我不知道如何 爲什麼會發生,或者是什麼意思。任何幫助感謝!

回答

2

聯繫人子系統在Android 2.0中完全改造。我並不感到驚訝的是,Uri"content://contacts/people/10"將無法​​正常工作,儘管我對您遇到的具體錯誤感到有點驚訝。這似乎是一個錯誤,因此您可能需要考慮打包一個演示錯誤並將其發佈到http://b.android.com的示例項目。

與此同時,你需要找出正確的Uri使用,因爲那不是它。如果您打算長時間堅持Uri的值,您可能需要基於CONTACT_LOOKUP_URI的數據。

+0

感謝馬克。我會爲它提交一個錯誤並嘗試你提出的替代方案。如果我能得到它的工作,我會在這裏發佈解決方案。 – user225405 2010-05-09 00:31:18

2

好了,經過一番實驗,下面的代碼對我的作品,這是我使用的是什麼(儘管它似乎比它應該是更多的工作):

 // 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); 
+0

究竟什麼是「contname」?你說它「是一個傳入的字符串」。它是聯繫人的名字嗎?還是一條路? – 2012-08-15 08:08:48

0

這個新解決問題版本:

String idContact = 10; 
Intent i; 
i = new Intent(Intent.ACTION_EDIT); 
i.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + idContact)); 
startActivity(i); 
+0

讓OP知道爲什麼 – dove 2012-12-01 18:00:04

相關問題