嘿,我想知道是否有办法知道召唤的内容提供商已经改变。我的意思是,如果我拨打电话,或者我接听电话,它会返回一个“标志”,表示已将新日志添加到通话记录或Android存储有关通话的信息的位置。如何知道电话的内容提供商已经改变
因为,当我拨打电话,Android的门店数量,联系人姓名(如果存在),调用,持续时间,等等等等,所有内容提供商的小时。那么是否有一种方法可以捕获这个“标志”,表示内容提供者的调用更大,我的意思是一个新的数据已经被插入到内容提供者CallLog.Calls中。
(更新)
所以,我还有很多与此问题相关的疑问。我不知道在哪里注册内容观察员。我的意图是,当CallLog内容提供者发生变化时,将使用代码的插入方法。
我的意思是,代码不会做任何事情,除非新的数据已经被添加到CallLog内容提供商。如果某些数据已添加到CallLog内容提供程序中,则代码将查询新数据,然后插入。我想这样做是因为在内容观察者应用程序将数据插入数据库时,每次运行应用程序时都已经插入数据,知道了吗?
因此,这里是我的代码。如果有人可以告诉我把registerContentObserver放在哪里,其他所有东西都需要,我感谢你。
package com.psyhclo;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import com.psyhclo.R;
import com.psyhclo.CallDataHelper.OpenHelper;
import android.app.Activity;
import android.app.ListActivity;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.content.ContentValues;
import android.content.Context;
import android.content.ContentProvider;
public class RatedCalls extends ListActivity {
private SQLiteDatabase db;
private CallDataHelper dh = null;
StringBuilder sb = new StringBuilder();
OpenHelper openHelper = new OpenHelper(RatedCalls.this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor cursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC ");
dh = new CallDataHelper(this);
db = openHelper.getWritableDatabase();
startManagingCursor(cursor);
int numberColumnId = cursor
.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int durationId = cursor
.getColumnIndex(android.provider.CallLog.Calls.DURATION);
int contactNameId = cursor
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME);
int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
int numTypeId = cursor
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NUMBER_TYPE);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String currTime = hours + ":" + minutes + ":" + seconds;
ArrayList<String> callList = new ArrayList<String>();
if (cursor.moveToFirst()) {
do {
String contactNumber = cursor.getString(numberColumnId);
String contactName = cursor.getString(contactNameId);
String duration = cursor.getString(durationId);
String callDate = DateFormat.getDateInstance().format(dateId);
String numType = cursor.getString(numTypeId);
ContentValues values = new ContentValues();
values.put("contact_id", 1);
values.put("contact_name", contactName);
values.put("number_type", numType);
values.put("contact_number", contactNumber);
values.put("duration", duration);
values.put("date", callDate);
values.put("current_time", currTime);
values.put("cont", 1);
this.db.insert(CallDataHelper.TABLE_NAME, null, values);
Toast.makeText(getBaseContext(), "Inserted!", Toast.LENGTH_LONG);
callList.add("Contact Number: " + contactNumber
+ "\nContact Name: " + contactName + "\nDuration: "
+ duration + "\nDate: " + callDate);
} while (cursor.moveToNext());
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem,
callList));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}