gpt4 book ai didi

android - 如何在 Android 中更新联系人的电子邮件、地址、昵称等?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:35:58 25 4
gpt4 key购买 nike

有人知道怎么做吗?甚至某些教程的链接也会有所帮助。

我使用的是搭载 Android 2.1 的设备。

最佳答案

请检查以下链接

update contact details on Android



创建 XML 文件“editcontmain.xml

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

<Button android:layout_width="fill_parent" android:id="@+id/EditContacts"
android:onClick="@string/clickEvent" android:layout_height="wrap_content"
android:text="Edit Contacts" />
</LinearLayout>

并创建java文件“EditContMain.java

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.util.Log;
import android.view.View;
import android.widget.Toast;

public class EditContMain extends Activity {

private static final int PICK_CONTACT = 0;
private static final int EDIT_CONTACT = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editcontmain);

}

public void clickHandler(View v) {
switch (v.getId()) {
case R.id.EditContacts:
Intent intent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
break;
default:
break;
}
}

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {
case (PICK_CONTACT):

if (resultCode == Activity.RESULT_OK) {

Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);

Log.e("c", c.getCount() + "");
if (c.moveToFirst()) {

String contactId = c.getString(c
.getColumnIndex(ContactsContract.Contacts._ID));

Toast.makeText(this, "ID = " + contactId, Toast.LENGTH_LONG)
.show();

Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(Uri
.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI
+ "/" + contactId));
startActivityForResult(i, EDIT_CONTACT);
}
}

break;
}
}
}

关于android - 如何在 Android 中更新联系人的电子邮件、地址、昵称等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6465905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com