Java 如何共享联系人
我有一个需要手机认证才能使用的应用程序。 认证后,我想设置一个功能,将能够共享其他联系人的人 例如,我是A,在我的联系人中有3个人使用我的应用程序B、C和D。 假设我想把B的联系人分享给D,我该怎么做 与在Whatsapp上共享联系人相同Java 如何共享联系人,java,android,share,Java,Android,Share,我有一个需要手机认证才能使用的应用程序。 认证后,我想设置一个功能,将能够共享其他联系人的人 例如,我是A,在我的联系人中有3个人使用我的应用程序B、C和D。 假设我想把B的联系人分享给D,我该怎么做 与在Whatsapp上共享联系人相同 搜索了很多,但没有得到如何实现这一点。实现这一点的一种方法是通过意图。您可以将数据存储在意图中,并通过 Intent intent = getIntent(); 然后在另一个屏幕中,通过以下方式检索相同的意图: String id = intent.getS
搜索了很多,但没有得到如何实现这一点。实现这一点的一种方法是通过意图。您可以将数据存储在意图中,并通过
Intent intent = getIntent();
然后在另一个屏幕中,通过以下方式检索相同的意图:
String id = intent.getStringExtra();
此外,您必须获得访问联系人的用户权限,然后通过intent传递联系人。需要在清单文件中添加权限。请尝试以下操作:
private void shareContact(String[] args) {
String lookupKey = null;
Cursor cur = getContentResolver().query(Contacts.CONTENT_URI, new String[] { Contacts.LOOKUP_KEY }, Contacts._ID + " = " + contactId, null, null);
if (cur.moveToFirst()) {
String lookupKey = cur.getString(0);
}
if(lookupKey!=null){
Uri vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE);
intent.putExtra(Intent.EXTRA_STREAM, shareUri);
intent.putExtra(Intent.EXTRA_SUBJECT, "Contact Name");
startActivity(intent);
}
}
更多详情:
试试这个:我相信它会有帮助
setContentView(R.layout.main);
contactNumber = (TextView)findViewById(R.id.contactnumber);
Button buttonPickContact = (Button)findViewById(R.id.pickcontact);
buttonPickContact.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, 1);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RQS_PICK_CONTACT){
if(resultCode == RESULT_OK){
Uri contactData = data.getData();
Cursor cursor = managedQuery(contactData, null, null, null, null);
cursor.moveToFirst();
String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
//contactName.setText(name);
contactNumber.setText(number);
//contactEmail.setText(email);
}
}
}
}
以下是相同的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" >
<Button
android:id="@+id/pickcontact"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pick Contact" />
<TextView
android:id="@+id/contactnumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
改进的格式您的联系人存储在哪里以及如何存储?您如何向“联系人”发送任何数据?短信?我已经储存在一个叫做“主屏幕”的活动中。。。因此,我可以使用intent并转到该活动,但如何单击其中一个项目并获取它呢@蟋蟀去拿什么?你能把你的代码显示为一个图标吗?您是否尝试过将联系人存储在SQLite中而不是活动中?我已将其存储在firebase中,活动仅在@cricket_007;取下它,因此我转到存储所有联系人的活动中。。。那我该怎么办?就像我需要编码如何从该活动中获取联系人一样,我可以使用一个意图,然后进入显示所有联系人的活动。。。但在那之后,我的问题是如何选择我想要的联系人之一