Hallo,
hab mich eben angemeldet und hab jetzt mal eben eine kleine Activity erstellt damit das ganze besser im Zusammenhang gesehen werden kann.
Ich hoffe das man so besser helfen kann.
Hier die Activity
package de.stf.android.contacts;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ContactPicker extends Activity {
private static final int CONTACT_PICKER_RESULT = 1001;
private static final String TAG = "ContactPicker";
Button btnReadContacts;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnReadContacts = (Button)findViewById(R.id.btnReadContacts);
btnReadContacts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
doLaunchContactPicker();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(resultCode == RESULT_OK){
switch (requestCode) {
case CONTACT_PICKER_RESULT:
ReadContactData(data);
break;
}
} else
{
Log.v(TAG, "Error: " + resultCode);
}
super.onActivityResult(requestCode, resultCode, data);
}
public void doLaunchContactPicker() {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
private void ReadContactData(Intent data)
{
Log.v(TAG, "data: " + data);
Uri dataUri = data.getData();
String contactId = dataUri.getLastPathSegment();
Log.v(TAG, "contactId " + contactId);
Cursor contactBrowser = null;
try{
contactBrowser = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID +" = ?",
new String[]{contactId},
null);
if(contactBrowser.moveToFirst())
{
String DisplayName = contactBrowser.getString(contactBrowser.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
Log.v(TAG, "DisplayName: " + DisplayName);
String FamilyName = contactBrowser.getString(contactBrowser.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
Log.v(TAG, "FamilyName: " + FamilyName);
String GivenName = contactBrowser.getString(contactBrowser.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
Log.v(TAG, "GivenName: " + GivenName);
String MiddleName = contactBrowser.getString(contactBrowser.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
Log.v(TAG, "MiddleName: " + MiddleName);
Cursor cPhone = getContentResolver().query(
Phone.CONTENT_URI, null,
Phone.CONTACT_ID + "=?",
new String[]{contactId}, null);
if(cPhone.moveToFirst())
{
String Phone_1 = cPhone.getString(cPhone.getColumnIndex(Phone.DATA));
Log.v(TAG, "Phone: " + Phone_1);
}
Log.v(TAG, "Schleife...");
int cols = contactBrowser.getColumnCount();
for(int x=0; x<cols;x++){
String colName = contactBrowser.getColumnName(x);
String colData = contactBrowser.getString(x);
Log.v(TAG,x + " =>> ColName: " + colName + "/t Data: " + colData);
}
}
} catch (Exception ee)
{
Log.v(TAG,"Exception: " + ee.toString());
} finally
{
if(contactBrowser != null){
contactBrowser.close();
}
}
}
}
Alles anzeigen
Das sollte eigentlich für die Profies hier selbsterklärend sein.
Ich hab 3 Kontakte angelegt mit Name, Vorname und Telefon.
Nun möchte ich eigentlich nur name, vorname und telefonnummern wieder ausgegeben haben.
Irgendwie gehts aber nicht.
Danke Euch
Matthias