0

I known the following code can call the system activity for contact list.

public void showSystemContactsUI(int requestCode) {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, requestCode);
}   

My question is how to call the system UI for the contacts' details, as the attached screenshot, Thx.enter image description here

Vipul
  • 27,808
  • 7
  • 60
  • 75
Tony Lin
  • 43
  • 1
  • 4

2 Answers2

1

You can use following code snippet. You would need to find target contact id before showing its details.

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);
Vipul
  • 27,808
  • 7
  • 60
  • 75
  • It works, Thank you. One more question if don't mind, if replace startActivity(intent) with startActivityForResult, Is it possible to pass the picked number back instead of dialling it. I have tried replace Intent.ACTION_VIEW with Intent.ACTION_PICK, but did not work. – Tony Lin Feb 11 '16 at 20:39
  • You can follow this post. http://stackoverflow.com/questions/9496350/pick-a-number-and-name-from-contacts-list-in-android-app. – Vipul Feb 12 '16 at 05:41
0

Create class call it IntentHelper and put all of related function to your systems (e.g Dial-Number , Send-SMS , View-in-Browser , ... ) in that like this :

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 "));
    }

}
Amir
  • 16,067
  • 10
  • 80
  • 119