A
A
Aitym Ramazanov2016-09-19 17:08:07
Android
Aitym Ramazanov, 2016-09-19 17:08:07

How to show a standard window that displays information about a specific contact?

In general, I study Android programming. In my application, when the button is pressed, a list of all contacts is shown:
9303d7b6078847fd90c1705eb0ed1e07.png
Next, the user selects a contact. Contact is selected, everything is fine. After that, I want the standard contact information window to be shown. For example:
04cd90a91c864a469b9d5e278a048b3f.png
But it doesn't happen. I'm trying to do it like this:
MainActivity.java:

// Показать список всех телефонных контактов и дать возможность пользователю выбрать один из них
public void viewContact() {
        // Start an activity for the user to pick a phone number from contacts
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent, REQUEST_VIEW_CONTACT_DETAILS);
        }
    }

// Пользовать выбрал контакт. Теперь надо отобразить о нем информацию
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_VIEW_CONTACT_DETAILS && resultCode == RESULT_OK) {
            Uri contactUri = data.getData();
            Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            } else {
                Toast.makeText(getApplicationContext(), "Can't resolve activity", Toast.LENGTH_LONG).show();
            }
        }
    }

AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.iteam91.commonintents">

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"></action>
                <category android:name="android.intent.category.LAUNCHER"></category>
            </intent-filter>
        </activity>

    </application>

</manifest>

I get a Toast "Can't resolve activity", i.e. intent.resolveActivity(getPackageManager()) is null (the system cannot match any activity for this case). Help me please.
PS Android version 4. 1. 2

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question