我想添加应用程序图标以及应用程序名称。在点击时应考虑应用。以下是我用于添加联系人(例如姓名,电话号码,电子邮件等)的工作代码。您能否建议添加应用程序图标和应用程序名称以用于应用程序的代码?我用谷歌搜索了一下,但是却得到了令人满意的答案。因此,为大家提供进一步的帮助。下面是我的代码:-
public static void addContact(Context context,Account account, String name, String username) {
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
builder.withValue(RawContacts.SYNC1, username);
operationList.add(builder.build());
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID,0);
builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
operationList.add(builder.build());
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
builder.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Photo.CONTACT_STATUS_ICON );
builder.withValue(ContactsContract.Data.DATA1, 4);
builder.withValue(ContactsContract.Data.DATA2, "user");
builder.withValue(ContactsContract.Data.DATA3, "MyData");
builder.withValue(ContactsContract.Data.CONTACT_STATUS_ICON, R.mipmap.ic_launcher);
operationList.add(builder.build());
mContentResolver = context.getContentResolver();
try {
mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.i(TAG, "Contact Name contact Exception: " + e);
e.printStackTrace();
}
}