我知道以下代码可以调用联系人列表的系统活动。
public void showSystemContactsUI(int requestCode) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, requestCode);
}
答案 0 :(得分:1)
您可以使用以下代码段。在显示详细信息之前,您需要找到目标联系人ID。
Uri uri = ContactsContract.Contacts.CONTENT_URI;
uri = Uri.withAppendedPath(uri, "1"); // 1 is contact id
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
答案 1 :(得分:0)
创建课程,将其称为 IntentHelper ,并将所有相关功能添加到您的系统中(例如拨号,发送短信,浏览器中,...)就像这样:
public class IntentHelper {
public static void dialNumber(Context context, String number) {
if (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", number, null));
context.startActivity(intent);
}
}
public static void sendEmail(Context context, String email) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
public static void viewInBrowser(Context context, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (null != intent.resolveActivity(context.getPackageManager())) {
context.startActivity(intent);
}
}
public static void shareOnSocials(Context context, String videoUrl) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, videoUrl);
context.startActivity(Intent.createChooser(intent, "share on "));
}
}