我需要在不同的手机上获取呼叫提供商的内部结构(这主要是因为三星设备会导致问题,即底层数据库架构)。这是我的代码:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
............................
dumpProvider();
}
private void dumpProvider() {
Cursor cursor = getCallsCursor();
try {
BufferedWriter writer = getWriter();
dumpColumnNames(cursor, writer);
cursor.moveToFirst();
do {
dumpRecord(cursor, writer);
} while (cursor.moveToNext());
writer.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
}
}
private void dumpRecord(Cursor cursor, BufferedWriter writer) throws IOException {
String recordStr = "";
int columnCount = cursor.getColumnCount();
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
recordStr += cursor.getString(columnIndex) + " ";
}
writer.append(recordStr);
writer.newLine();
}
private void dumpColumnNames(Cursor cursor, BufferedWriter writer) throws IOException {
String[] columnNames = cursor.getColumnNames();
String columnNamesStr = "";
for (String columnStr : columnNames) {
columnNamesStr += columnStr + " ";
}
writer.append(columnNamesStr);
writer.newLine();
}
private Cursor getCallsCursor() {
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, null, null, null, null);
return cursor;
}
private BufferedWriter getWriter() throws IOException {
......................
}
}
在我的 LG 上运行良好,但在三星 S2 上运行时出现异常:
08-20 09:16:15.860: E/AndroidRuntime(19565): FATAL EXCEPTION: main
08-20 09:16:15.860: E/AndroidRuntime(19565): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.databasestrucutecollector/com.example.databasestrucutecollector.MainActivity}: android.database.sqlite.SQLiteException: no such column: sdn_alpha_id: , while compiling: SELECT sns_receiver_count, numberlabel, service_type, matched_number, type, contactid, lookup_uri, mime_type, sdn_alpha_id, sp_type, messageid, fname, simnum, lname, sns_pkey, account_id, formatted_number, call_out_duration, number, geocoded_location, account_name, is_read, raw_contact_id, source_data, cdnip_number, state, m_subject, date, real_phone_number, source_package, _id, sns_tid, name, normalized_number, name_reversed, _data, photo_id, logtype, reject_flag, has_content, m_content, country_code, frequent, cityid, bname, countryiso, numbertype, new, duration, cnap_name, address, e164_number, voicemail_uri FROM logs WHERE (logs.logtype=100 OR logs.logtype=110 OR logs.logtype=500 OR logs.logtype=800 OR logs.logtype=900 OR logs.logtype=1000 OR (logs.logtype=200 AND number NOT IN (SELECT number FROM logs WHERE number LIKE '%@%')) OR logs.logtype=300) AND ((((type != '4')))) ORDER BY date DESC
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread.access$600(ActivityThread.java:127)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.os.Looper.loop(Looper.java:137)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread.main(ActivityThread.java:4511)
08-20 09:16:15.860: E/AndroidRuntime(19565): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 09:16:15.860: E/AndroidRuntime(19565): at java.lang.reflect.Method.invoke(Method.java:511)
08-20 09:16:15.860: E/AndroidRuntime(19565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
08-20 09:16:15.860: E/AndroidRuntime(19565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
08-20 09:16:15.860: E/AndroidRuntime(19565): at dalvik.system.NativeStart.main(Native Method)
08-20 09:16:15.860: E/AndroidRuntime(19565): Caused by: android.database.sqlite.SQLiteException: no such column: sdn_alpha_id: , while compiling: SELECT sns_receiver_count, numberlabel, service_type, matched_number, type, contactid, lookup_uri, mime_type, sdn_alpha_id, sp_type, messageid, fname, simnum, lname, sns_pkey, account_id, formatted_number, call_out_duration, number, geocoded_location, account_name, is_read, raw_contact_id, source_data, cdnip_number, state, m_subject, date, real_phone_number, source_package, _id, sns_tid, name, normalized_number, name_reversed, _data, photo_id, logtype, reject_flag, has_content, m_content, country_code, frequent, cityid, bname, countryiso, numbertype, new, duration, cnap_name, address, e164_number, voicemail_uri FROM logs WHERE (logs.logtype=100 OR logs.logtype=110 OR logs.logtype=500 OR logs.logtype=800 OR logs.logtype=900 OR logs.logtype=1000 OR (logs.logtype=200 AND number NOT IN (SELECT number FROM logs WHERE number LIKE '%@%')) OR logs.logtype=300) AND ((((type != '4')))) ORDER BY date DESC
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:180)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.content.ContentResolver.query(ContentResolver.java:317)
08-20 09:16:15.860: E/AndroidRuntime(19565): at com.example.databasestrucutecollector.MainActivity.getContactsCursor(MainActivity.java:71)
08-20 09:16:15.860: E/AndroidRuntime(19565): at com.example.databasestrucutecollector.MainActivity.dumpProvider(MainActivity.java:31)
08-20 09:16:15.860: E/AndroidRuntime(19565): at com.example.databasestrucutecollector.MainActivity.onCreate(MainActivity.java:26)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.Activity.performCreate(Activity.java:4470)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
08-20 09:16:15.860: E/AndroidRuntime(19565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
有什么提示吗?