大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
郑州app开发查询联系人数据过程。布局代码只是一个button。以下是java代码
创新互联公司-专业网站定制、快速模板网站建设、高性价比镶黄网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式镶黄网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖镶黄地区。费用合理售后完善,十多年实体公司更值得信赖。
MainActivity.java
package cn.xhhkj.cyd;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.bundle;
import android.os.Ibinder;
import android.util.Log;
import android.util.Xml;
import android.view.View;
import org.xmlpull.v1.XmlSerializer;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "结果是";
private ArrayList
@Override
protected void onCreate(bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void query(View view) {
ContentResolver resolver = getContentResolver();
Uri raw_contact_uri = Uri.parse("content://com.android.contacts/raw_contacts");
Uri data_uri = Uri.parse("content://com.android.contacts/data");
Cursor cursor = resolver.query(raw_contact_uri, new String[]{"contact_id"}, null, null, null);
while(cursor.moveToNext()){
String id = cursor.getString(0);
Log.d(TAG,"id"+id);
String[] projection ={"data1","mimetype"};
Contact contact = new Contact();
Cursor cursor2 = resolver.query(data_uri, projection, "raw_contact_id=?", new String[]{id}, null);
while(cursor2.moveToNext()){
String result = cursor2.getString(0);
String type = cursor2.getString(1);
Log.d(TAG,result+"====="+type);
if("vnd.android.cursor.item/phone_v2".equals(type)){
contact.phone = result;
}else if("vnd.android.cursor.item/email_v2".equals(type)){
contact.email = result;
}else if("vnd.android.cursor.item/name".equals(type)){
contact.name = result;
}else if("vnd.android.cursor.item/postal-address_v2".equals(type)){
contact.address = result;
}
}
contacts.add(contact);
}
for(Contact contact:contacts){
System.out.println(contact);
Log.d(TAG,"contact"+contact);
}
}
}
Contact.java
package cn.xhhkj.cyd;
public class Contact {
public String name;
public String address;
public String email;
public String phone;
@Override
public String toString() {
return "Contact [name=" + name + ", address=" + address + ", email="
+ email + ", phone=" + phone + "]";
}
}