Answer the question
In order to leave comments, you need to log in
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:
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:
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();
}
}
}
<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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question