いくつかの調査とコーディングの後、callLog にアクセスできるようになりました。callLog から編集テキストに番号を取得できるようにコードを追加した後、エラーが発生したようです。私はこれをグーグルで検索しましたが、これまでのところ役に立ちません。何かアドバイスはありますか?-サイモン-
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class SimonCallLogActivity extends Activity {
/** Called when the activity is first created. */
EditText display;
Button log;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//to go to Call Log//
log=(Button)findViewById(R.id.button1);
log.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent myIntent=new Intent();
myIntent.setAction(Intent.ACTION_CALL_BUTTON);
startActivity(myIntent);
}
});
}
//Call Log//
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
final EditText number = (EditText) findViewById(R.id.editText1);
Cursor cursor = null;
String phoneNo = " ";
List<String> logNumbers = new ArrayList<String>();
String[] projection = new String[] {CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.CACHED_NAME};
Uri contacts = CallLog.Calls.CONTENT_URI;
Cursor managedCursor = managedQuery(contacts, projection, null, null, CallLog.Calls.DATE + " ASC");
getColumnData(managedCursor);
}
private void getColumnData(Cursor cur){
try{
if (cur.moveToFirst()) {
String name;
String number;
long date;
int nameColumn = cur.getColumnIndex(CallLog.Calls.CACHED_NAME);
int numberColumn = cur.getColumnIndex(CallLog.Calls.NUMBER);
int dateColumn = cur.getColumnIndex(CallLog.Calls.DATE);
System.out.println("Reading Call Details: ");
do {
name = cur.getString(nameColumn);
number = cur.getString(numberColumn);
date = cur.getLong(dateColumn);
System.out.println(number + ":"+ new Date(date) +":"+name);
// number.setText(numberColumn);
} while (cur.moveToNext());
}
}
finally
{
cur.close();
}
final String [] items = logNumbers.toArray(new String[logNumbers.size() ]) ;
AlertDialog.Builder builder = new AlertDialog.Builder(SimonCallLogActivity.this);
builder.setTitle("Choose a number: ");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// TODO Auto-generated method stub
String selectedNumber = items[item].toString();
selectedNumber= selectedNumber.replace("-","");
selectedNumber= selectedNumber.replace("Home:", "");
selectedNumber= selectedNumber.replace("Mobile:", "");
selectedNumber= selectedNumber.replace("Work:", "");
selectedNumber= selectedNumber.replace("Other:", "");
//selectedNumber = selectedNumber.replace("+","");
number.setText(selectedNumber);
}
});
AlertDialog alert = builder.create();
if(logNumbers.size()>1){
alert.show();
}else{
String selectedNumber= phoneNo.toString();
selectedNumber=selectedNumber.replace("-", "");
number.setText(selectedNumber);
}
if(phoneNo.length()==0){
Log.d("SIMON", "No contact");
}
}
break;
}
}else
{
//gracefully handle failure
Log.w("SIMON","Warning activity not okay");
}
}
}