android应用开发之清除通话记录
通话记录的操作是通过ContactsProvider来玩的,具体的操作晚上大把的例子。摘录下主要部分:数据库:/data/data/com.android.providers.contacts/databases/contacts2.db
表名: calls
呼叫类型:
来电:CallLog.Calls.INCOMING_TYPE (常量值:1)
已拨:CallLog.Calls.OUTGOING_TYPE(常量值:2)
未接:CallLog.Calls.MISSED_TYPE(常量值:3)
源代码中的provider的声明如下:
packages\providers\ContactsProvider\AndroidManifest.xml
[plain]
<provider android:name="CallLogProvider"
android:authorities="call_log"
android:syncable="false" android:multiprocess="false"
android:exported="true"
android:readPermission="android.permission.READ_CALL_LOG"
android:writePermission="android.permission.WRITE_CALL_LOG">
</provider>
勿忘声明权限袄
【二、实例】
ThreadCleanCallLogActivity
[java]
package cn.test.cleancalllog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInte易做图ce;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.CallLog;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class ThreadCleanCallLogActivity extends Activity implements
OnClickListener {
private boolean isExits = false;
private boolean isGoOn = true;
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
cleanCallLog();
}
};
<span style="white-space:pre"> </span>//其实就核心方法就这个方法中的几行代码。
private void cleanCallLog() {
ContentResolver resolver = getContentResolver();
resolver.delete(CallLog.Calls.CONTENT_URI, null, null);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("清除通话记录!");
// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
init();
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_about:
Log.e("Other", "you click the about item!");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name)
.setMessage("本程序由流浪天堂开发 联系作者:sanbo.xyz@gmail.com")
.setCancelable(true)
.setPositiveButton("确定",
new DialogInte易做图ce.OnClickListener() {
public void onClick(DialogInte易做图ce dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
break;
case R.id.menu_exit:
Log.e("Other", "you click exit item!");
finish();
break;
default:
break;
}
return false;
}
private void init() {
this.findViewById(R.id.btnThread).setOnClickListener(this);
}
public void onClick(View v) {
if (v.getId() == R.id.btnThread) {
if (!isExits) {
isExits = true;
new MyThread().start();
Toast.makeText(getApplicationContext(), "删除完成!", 0).show();
&
补充:移动开发 , Android ,