android 응용 프로그램 개발 통화 기록 지우기

6049 단어
[1. 대략적인 소개]
통화기록의 조작은Contacts Provider를 통해 이루어진 것으로 구체적인 조작은 저녁에 많이 하는 예이다.아래 주요 섹션을 발췌합니다.
데이터베이스:/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
<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>

성명 권한 저고리
【2. 실례】
ThreadCleanCallLogActivity
package cn.test.cleancalllog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
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();
		}

	};
	// 。
	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("                                 :[email protected]")
					.setCancelable(true)
					.setPositiveButton(" ",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface 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();
			} else {
				Toast.makeText(getApplicationContext(), " , !", 0).show();
			}
		}

	}

	class MyThread extends Thread {

		public void run() {
			super.run();
			while (isGoOn) {
				try {
					sleep(30);
					Message msg = new Message();
					handler.sendMessage(msg);
					isGoOn = false;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		}
	}

}

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/test">


    <Button
        android:id="@+id/btnThread"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="threadhandler" 
        android:background="@drawable/buttonselect"
        android:gravity="center"
        />
</LinearLayout>

menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/menu_about" android:title=" " /> 
    <item android:id="@+id/menu_exit" android:title=" " />
</menu>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.test.cleancalllog"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".ThreadCleanCallLogActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
</manifest>

좋은 웹페이지 즐겨찾기